Skip to content

Commit d8466d4

Browse files
committed
fix: use form control mixin in uui-button
1 parent de5cf72 commit d8466d4

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/uui-button/lib/uui-button.element.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
UUIHorizontalShakeKeyframes,
44
} from '@umbraco-ui/uui-base/lib/animations';
55
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';
77
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
88
import {
99
InterfaceLookDefaultValue,
@@ -14,7 +14,7 @@ import {
1414
iconWrong,
1515
} from '@umbraco-ui/uui-icon-registry-essential/lib/svgs';
1616
import { css, html, LitElement } from 'lit';
17-
import { property } from 'lit/decorators.js';
17+
import { property, query } from 'lit/decorators.js';
1818

1919
export type UUIButtonState = null | 'waiting' | 'success' | 'failed';
2020

@@ -41,7 +41,9 @@ export type UUIButtonType = 'submit' | 'button' | 'reset';
4141
* @cssprop --uui-button-contrast-disabled - overwrite the text color for disabled state
4242
*/
4343
@defineElement('uui-button')
44-
export class UUIButtonElement extends LabelMixin('', LitElement) {
44+
export class UUIButtonElement extends FormControlMixin(
45+
LabelMixin('', LitElement)
46+
) {
4547
static styles = [
4648
UUIHorizontalShakeKeyframes,
4749
css`
@@ -554,20 +556,18 @@ export class UUIButtonElement extends LabelMixin('', LitElement) {
554556
@property({ type: String, reflect: true })
555557
state: UUIButtonState = null;
556558

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;
564561

565562
constructor() {
566563
super();
567-
this._internals = (this as any).attachInternals();
568564
this.addEventListener('click', this._onHostClick);
569565
}
570566

567+
protected getFormElement(): HTMLElement {
568+
return this._button;
569+
}
570+
571571
private _onHostClick(e: MouseEvent) {
572572
if (this.disabled) {
573573
e.preventDefault();
@@ -637,7 +637,7 @@ export class UUIButtonElement extends LabelMixin('', LitElement) {
637637

638638
render() {
639639
return html`
640-
<button ?disabled=${this.disabled} aria-label="${this.label}">
640+
<button id="button" ?disabled=${this.disabled} aria-label="${this.label}">
641641
${this.renderState()} ${this.renderLabel()}
642642
<slot name="extra"></slot>
643643
</button>

0 commit comments

Comments
 (0)