11import type { EventEmitter } from '@stencil/core' ;
2- import { Component , Event , h , Prop } from '@stencil/core' ;
2+ import { Component , Element , 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,6 +10,8 @@ import type { ButtonSizeEnum, ButtonVariantEnum } from '../../../common/Button/b
1010 shadow : true ,
1111} )
1212export class Button {
13+ @Element ( ) hostElement ! : HTMLElement ;
14+
1315 @Event ( ) buttonClick : EventEmitter < MouseEvent > ;
1416
1517 @Prop ( ) class ?: string = '' ;
@@ -18,6 +20,19 @@ export class Button {
1820 @Prop ( ) size ?: `${ButtonSizeEnum } ` = 'large' ;
1921 @Prop ( ) variant ?: `${ButtonVariantEnum } ` = 'primary' ;
2022
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+
2136 private handleClick = ( event : MouseEvent ) => {
2237 this . buttonClick . emit ( event ) ;
2338 } ;
0 commit comments