@@ -3,6 +3,7 @@ import { classMap } from 'lit/directives/class-map.js';
3
3
import { ifDefined } from 'lit/directives/if-defined.js' ;
4
4
import { html , literal } from 'lit/static-html.js' ;
5
5
import { WaInvalidEvent } from '../../events/invalid.js' ;
6
+ import { HasSlotController } from '../../internal/slot.js' ;
6
7
import { MirrorValidator } from '../../internal/validators/mirror-validator.js' ;
7
8
import { watch } from '../../internal/watch.js' ;
8
9
import { WebAwesomeFormAssociatedElement } from '../../internal/webawesome-form-associated-element.js' ;
@@ -61,11 +62,11 @@ export default class WaButton extends WebAwesomeFormAssociatedElement {
61
62
}
62
63
63
64
assumeInteractionOn = [ 'click' ] ;
65
+ private readonly hasSlotController = new HasSlotController ( this , '[default]' , 'prefix' , 'suffix' ) ;
64
66
private readonly localize = new LocalizeController ( this ) ;
65
67
66
68
@query ( '.wa-button' ) button : HTMLButtonElement | HTMLLinkElement ;
67
69
68
- @state ( ) visuallyHiddenLabel = false ;
69
70
@state ( ) invalid = false ;
70
71
@property ( ) title = '' ; // make reactive to pass through
71
72
@@ -184,15 +185,6 @@ export default class WaButton extends WebAwesomeFormAssociatedElement {
184
185
this . dispatchEvent ( new WaInvalidEvent ( ) ) ;
185
186
}
186
187
187
- private handleLabelSlotChange ( event : Event ) {
188
- // If the only thing slotted in is a visually hidden element, we consider it a visually hidden label and apply a
189
- // class so we can adjust styles accordingly.
190
- const elements = ( event . target as HTMLSlotElement ) . assignedElements ( { flatten : true } ) ;
191
- if ( elements . length === 1 && elements [ 0 ] . localName === 'wa-visually-hidden' ) {
192
- this . visuallyHiddenLabel = true ;
193
- }
194
- }
195
-
196
188
private isButton ( ) {
197
189
return this . href ? false : true ;
198
190
}
@@ -243,7 +235,9 @@ export default class WaButton extends WebAwesomeFormAssociatedElement {
243
235
disabled : this . disabled ,
244
236
loading : this . loading ,
245
237
rtl : this . localize . dir ( ) === 'rtl' ,
246
- 'visually-hidden-label' : this . visuallyHiddenLabel ,
238
+ 'has-label' : this . hasSlotController . test ( '[default]' ) ,
239
+ 'has-prefix' : this . hasSlotController . test ( 'prefix' ) ,
240
+ 'has-suffix' : this . hasSlotController . test ( 'suffix' ) ,
247
241
} ) }
248
242
?disabled=${ ifDefined ( isLink ? undefined : this . disabled ) }
249
243
type=${ ifDefined ( isLink ? undefined : this . type ) }
@@ -261,7 +255,7 @@ export default class WaButton extends WebAwesomeFormAssociatedElement {
261
255
@click=${ this . handleClick }
262
256
>
263
257
< slot name ="prefix " part ="prefix " class ="prefix "> </ slot >
264
- < slot part ="label " class ="label " @slotchange = ${ this . handleLabelSlotChange } > </ slot >
258
+ < slot part ="label " class ="label "> </ slot >
265
259
< slot name ="suffix " part ="suffix " class ="suffix "> </ slot >
266
260
${
267
261
this . caret
0 commit comments