77import '../../focus/md-focus-ring.js' ;
88import '../../ripple/ripple.js' ;
99
10- import { html , LitElement , PropertyValues , TemplateResult } from 'lit' ;
10+ import { html , isServer , LitElement , PropertyValues , TemplateResult } from 'lit' ;
1111import { property } from 'lit/decorators.js' ;
1212import { ClassInfo , classMap } from 'lit/directives/class-map.js' ;
1313
@@ -35,12 +35,25 @@ export abstract class Chip extends chipBaseClass {
3535 */
3636 @property ( { type : Boolean , reflect : true } ) disabled = false ;
3737
38+ /**
39+ * Whether or not the chip is "soft-disabled" (disabled but still
40+ * focusable).
41+ *
42+ * Use this when a chip needs increased visibility when disabled. See
43+ * https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls
44+ * for more guidance on when this is needed.
45+ */
46+ @property ( { type : Boolean , attribute : 'soft-disabled' , reflect : true } )
47+ softDisabled = false ;
48+
3849 /**
3950 * When true, allow disabled chips to be focused with arrow keys.
4051 *
4152 * Add this when a chip needs increased visibility when disabled. See
4253 * https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls
4354 * for more guidance on when this is needed.
55+ *
56+ * @deprecated Use `softDisabled` instead of `alwaysFocusable` + `disabled`.
4457 */
4558 @property ( { type : Boolean , attribute : 'always-focusable' } )
4659 alwaysFocusable = false ;
@@ -70,7 +83,14 @@ export abstract class Chip extends chipBaseClass {
7083 * Some chip actions such as links cannot be disabled.
7184 */
7285 protected get rippleDisabled ( ) {
73- return this . disabled ;
86+ return this . disabled || this . softDisabled ;
87+ }
88+
89+ constructor ( ) {
90+ super ( ) ;
91+ if ( ! isServer ) {
92+ this . addEventListener ( 'click' , this . handleClick . bind ( this ) ) ;
93+ }
7494 }
7595
7696 override focus ( options ?: FocusOptions ) {
@@ -97,7 +117,7 @@ export abstract class Chip extends chipBaseClass {
97117
98118 protected getContainerClasses ( ) : ClassInfo {
99119 return {
100- 'disabled' : this . disabled ,
120+ 'disabled' : this . disabled || this . softDisabled ,
101121 'has-icon' : this . hasIcon ,
102122 } ;
103123 }
@@ -139,4 +159,15 @@ export abstract class Chip extends chipBaseClass {
139159 const slot = event . target as HTMLSlotElement ;
140160 this . hasIcon = slot . assignedElements ( { flatten : true } ) . length > 0 ;
141161 }
162+
163+ private handleClick ( event : Event ) {
164+ // If the chip is soft-disabled or disabled + always-focusable, we need to
165+ // explicitly prevent the click from propagating to other event listeners
166+ // as well as prevent the default action.
167+ if ( this . softDisabled || ( this . disabled && this . alwaysFocusable ) ) {
168+ event . stopImmediatePropagation ( ) ;
169+ event . preventDefault ( ) ;
170+ return ;
171+ }
172+ }
142173}
0 commit comments