99// This is required for @ariaProperty
1010// tslint:disable:no-new-decorators
1111
12- import '../../icon/icon.js' ;
1312import '../../focus/focus-ring.js' ;
1413import '../../ripple/ripple.js' ;
1514
16- import { html , LitElement , TemplateResult } from 'lit' ;
15+ import { html , LitElement , nothing , TemplateResult } from 'lit' ;
1716import { property , query , queryAssignedElements , queryAsync , state } from 'lit/decorators.js' ;
1817import { ClassInfo , classMap } from 'lit/directives/class-map.js' ;
19- import { ifDefined } from 'lit/directives/if-defined.js' ;
2018import { when } from 'lit/directives/when.js' ;
21- import { html as staticHtml , literal } from 'lit/static-html.js' ;
2219
2320import { dispatchActivationClick , isActivationClick } from '../../controller/events.js' ;
2421import { ariaProperty } from '../../decorators/aria-property.js' ;
@@ -34,8 +31,6 @@ export abstract class Button extends LitElement implements ButtonState {
3431 static override shadowRootOptions :
3532 ShadowRootInit = { mode : 'open' , delegatesFocus : true } ;
3633
37- protected readonly iconTag = literal `md-icon` ;
38-
3934 @property ( { type : String , attribute : 'data-aria-has-popup' , noAccessor : true } )
4035 @ariaProperty
4136 override ariaHasPopup ! : ARIAHasPopup ;
@@ -57,13 +52,6 @@ export abstract class Button extends LitElement implements ButtonState {
5752 */
5853 @property ( { type : Boolean , attribute : 'trailingicon' } ) trailingIcon = false ;
5954
60- /**
61- * The label of the icon to render.
62- *
63- * See md-icon's documentation for usage.
64- */
65- @property ( { type : String } ) icon = '' ;
66-
6755 /**
6856 * The button's visible label.
6957 */
@@ -90,7 +78,7 @@ export abstract class Button extends LitElement implements ButtonState {
9078 @state ( ) protected showRipple = false ;
9179
9280 @queryAssignedElements ( { slot : 'icon' , flatten : true } )
93- protected iconElement ! : HTMLElement [ ] | null ;
81+ protected assignedIcons ! : HTMLElement [ ] ;
9482
9583 constructor ( ) {
9684 super ( ) ;
@@ -124,8 +112,8 @@ export abstract class Button extends LitElement implements ButtonState {
124112 < button
125113 class ="md3-button ${ classMap ( this . getRenderClasses ( ) ) } "
126114 ?disabled ="${ this . disabled } "
127- aria-label="${ ifDefined ( this . ariaLabel || undefined ) } "
128- aria-haspopup="${ ifDefined ( this . ariaHasPopup || undefined ) } "
115+ aria-label ="${ this . ariaLabel || nothing } "
116+ aria-haspopup ="${ this . ariaHasPopup || nothing } "
129117 @pointerdown ="${ this . handlePointerDown } "
130118 @focus ="${ this . handleFocus } "
131119 @blur ="${ this . handleBlur } "
@@ -196,23 +184,10 @@ export abstract class Button extends LitElement implements ButtonState {
196184 return html `< span class ="md3-button__icon-slot-container ${
197185 classMap ( this . getIconContainerClasses ( ) ) } ">
198186 < slot name ="icon " @slotchange ="${ this . handleSlotChange } ">
199- ${ this . icon ? this . renderFontIcon ( ) : '' }
200187 </ slot >
201188 </ span > ` ;
202189 }
203190
204- protected renderFontIcon ( ) : TemplateResult {
205- return staticHtml `
206- <${ this . iconTag } class="md3-button__icon">
207- ${ this . icon }
208- </${ this . iconTag } >` ;
209- }
210-
211- override update ( changedProperties : Map < string , string > ) {
212- super . update ( changedProperties ) ;
213- this . hasIcon = ! ! this . iconElement && this . iconElement . length > 0 ;
214- }
215-
216191 protected handlePointerDown ( e : PointerEvent ) {
217192 pointerPress ( ) ;
218193 this . showFocusRing = shouldShowStrongFocus ( ) ;
@@ -233,6 +208,6 @@ export abstract class Button extends LitElement implements ButtonState {
233208 }
234209
235210 protected handleSlotChange ( ) {
236- this . requestUpdate ( ) ;
211+ this . hasIcon = this . assignedIcons . length > 0 ;
237212 }
238213}
0 commit comments