3
3
UUIHorizontalShakeKeyframes ,
4
4
} from '@umbraco-ui/uui-base/lib/animations' ;
5
5
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils' ;
6
- import { LabelMixin } from '@umbraco-ui/uui-base/lib/mixins' ;
6
+ import { FormControlMixin , LabelMixin } from '@umbraco-ui/uui-base/lib/mixins' ;
7
7
import { defineElement } from '@umbraco-ui/uui-base/lib/registration' ;
8
8
import {
9
9
InterfaceLookDefaultValue ,
@@ -14,7 +14,7 @@ import {
14
14
iconWrong ,
15
15
} from '@umbraco-ui/uui-icon-registry-essential/lib/svgs' ;
16
16
import { css , html , LitElement } from 'lit' ;
17
- import { property } from 'lit/decorators.js' ;
17
+ import { property , query } from 'lit/decorators.js' ;
18
18
19
19
export type UUIButtonState = null | 'waiting' | 'success' | 'failed' ;
20
20
@@ -41,7 +41,9 @@ export type UUIButtonType = 'submit' | 'button' | 'reset';
41
41
* @cssprop --uui-button-contrast-disabled - overwrite the text color for disabled state
42
42
*/
43
43
@defineElement ( 'uui-button' )
44
- export class UUIButtonElement extends LabelMixin ( '' , LitElement ) {
44
+ export class UUIButtonElement extends FormControlMixin (
45
+ LabelMixin ( '' , LitElement )
46
+ ) {
45
47
static styles = [
46
48
UUIHorizontalShakeKeyframes ,
47
49
css `
@@ -554,20 +556,18 @@ export class UUIButtonElement extends LabelMixin('', LitElement) {
554
556
@property ( { type : String , reflect : true } )
555
557
state : UUIButtonState = null ;
556
558
557
- /**
558
- * This is a static class field indicating that the element is can be used inside a native form and participate in its events. It may require a polyfill, check support here https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/attachInternals. Read more about form controls here https://web.dev/more-capable-form-controls/
559
- * @type {boolean }
560
- */
561
- static readonly formAssociated = true ;
562
-
563
- private _internals ;
559
+ @query ( '#button' )
560
+ protected _button ! : HTMLInputElement ;
564
561
565
562
constructor ( ) {
566
563
super ( ) ;
567
- this . _internals = ( this as any ) . attachInternals ( ) ;
568
564
this . addEventListener ( 'click' , this . _onHostClick ) ;
569
565
}
570
566
567
+ protected getFormElement ( ) : HTMLElement {
568
+ return this . _button ;
569
+ }
570
+
571
571
private _onHostClick ( e : MouseEvent ) {
572
572
if ( this . disabled ) {
573
573
e . preventDefault ( ) ;
@@ -637,7 +637,7 @@ export class UUIButtonElement extends LabelMixin('', LitElement) {
637
637
638
638
render ( ) {
639
639
return html `
640
- < button ?disabled =${ this . disabled } aria-label ="${ this . label } ">
640
+ < button id =" button " ?disabled =${ this . disabled } aria-label ="${ this . label } ">
641
641
${ this . renderState ( ) } ${ this . renderLabel ( ) }
642
642
< slot name ="extra "> </ slot >
643
643
</ button >
0 commit comments