11import type { EventEmitter } from '@stencil/core' ;
2- import { Component , Element , Event , h , Prop } from '@stencil/core' ;
2+ import { Component , Event , h , Prop } from '@stencil/core' ;
33import { Button as ButtonComponent } from 'common/Button/Button' ;
44
55import type { ButtonSizeEnum , ButtonVariantEnum } from '../../../common/Button/button.types' ;
@@ -10,29 +10,16 @@ import type { ButtonSizeEnum, ButtonVariantEnum } from '../../../common/Button/b
1010 shadow : true ,
1111} )
1212export class Button {
13- @Element ( ) hostElement ! : HTMLElement ;
14-
1513 @Event ( ) buttonClick : EventEmitter < MouseEvent > ;
1614
1715 @Prop ( ) class ?: string = '' ;
18- @Prop ( { attribute : 'data-testid' } ) dataTestId ?: string = '' ;
16+ // Accept `data-testid` without reflecting it on the host element,
17+ // so only the inner `<button>` ends up with this attribute.
18+ @Prop ( { attribute : 'data-testid' , reflect : false } ) dataTestId ?: string = '' ;
1919 @Prop ( ) disabled ?: boolean = false ;
2020 @Prop ( ) size ?: `${ButtonSizeEnum } ` = 'large' ;
2121 @Prop ( ) variant ?: `${ButtonVariantEnum } ` = 'primary' ;
2222
23- /**
24- * Stencil reflects `data-testid` to the host element based on the Prop decorator above.
25- * That causes two DOM nodes with the same `data-testid`: the `<mvx-button>` host and
26- * the inner `<button>`, which breaks Playwright strict mode. We keep using the
27- * attribute to populate `dataTestId`, but remove it from the host after render so that
28- * only the inner `<button>` keeps the `data-testid`.
29- */
30- componentDidRender ( ) {
31- if ( this . hostElement . hasAttribute ( 'data-testid' ) ) {
32- this . hostElement . removeAttribute ( 'data-testid' ) ;
33- }
34- }
35-
3623 private handleClick = ( event : MouseEvent ) => {
3724 this . buttonClick . emit ( event ) ;
3825 } ;
0 commit comments