@material/web 2.3.0 → 2.3.1-nightly.c72650f.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -92,8 +92,7 @@ export class Button extends buttonBaseClass {
|
|
|
92
92
|
this.buttonElement?.blur();
|
|
93
93
|
}
|
|
94
94
|
render() {
|
|
95
|
-
|
|
96
|
-
const isRippleDisabled = !this.href && (this.disabled || this.softDisabled);
|
|
95
|
+
const isRippleDisabled = this.disabled || this.softDisabled;
|
|
97
96
|
const buttonOrLink = this.href ? this.renderLink() : this.renderButton();
|
|
98
97
|
// TODO(b/310046938): due to a limitation in focus ring/ripple, we can't use
|
|
99
98
|
// the same ID for different elements, so we change the ID instead.
|
|
@@ -132,6 +131,8 @@ export class Button extends buttonBaseClass {
|
|
|
132
131
|
aria-label="${ariaLabel || nothing}"
|
|
133
132
|
aria-haspopup="${ariaHasPopup || nothing}"
|
|
134
133
|
aria-expanded="${ariaExpanded || nothing}"
|
|
134
|
+
aria-disabled=${this.disabled || this.softDisabled || nothing}
|
|
135
|
+
tabindex="${this.disabled && !this.softDisabled ? -1 : nothing}"
|
|
135
136
|
href=${this.href}
|
|
136
137
|
download=${this.download || nothing}
|
|
137
138
|
target=${this.target || nothing}
|
|
@@ -150,10 +151,10 @@ export class Button extends buttonBaseClass {
|
|
|
150
151
|
`;
|
|
151
152
|
}
|
|
152
153
|
handleClick(event) {
|
|
153
|
-
// If the button is soft-disabled, we need to explicitly
|
|
154
|
-
// from propagating to other event listeners as well as
|
|
155
|
-
// action.
|
|
156
|
-
if (
|
|
154
|
+
// If the button is soft-disabled or a disabled link, we need to explicitly
|
|
155
|
+
// prevent the click from propagating to other event listeners as well as
|
|
156
|
+
// prevent the default action.
|
|
157
|
+
if (this.softDisabled || (this.disabled && this.href)) {
|
|
157
158
|
event.stopImmediatePropagation();
|
|
158
159
|
event.preventDefault();
|
|
159
160
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{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AAI,CAAC,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/C,CAAC;;AApMD;IACE,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC,GAAA,CAAA;AAED,kBAAkB;AACF,qBAAc,GAAG,IAAI,AAAP,CAAQ;AAEtC,kBAAkB;AACF,wBAAiB,GAAmB;IAClD,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,IAAI;CACrB,AAHgC,CAG/B;AAKwC;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;wCAAkB;AAW3D;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;4CAChD;AAKT;IAAX,QAAQ,EAAE;oCAAW;AAOV;IAAX,QAAQ,EAAE;wCAAe;AAMd;IAAX,QAAQ,EAAE;sCAA2D;AAStE;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;4CAChD;AAK4C;IAAhE,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;uCACxD;AAMI;IAAX,QAAQ,EAAE;oCAAoC;AAMpB;IAA1B,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;qCAAY;AAgBH;IAAlC,KAAK,CAAC,SAAS,CAAC;6CAAqD;AAGrD;IADhB,qBAAqB,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CACN","sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport '../../focus/md-focus-ring.js';\nimport '../../ripple/ripple.js';\n\nimport {html, isServer, LitElement, nothing} from 'lit';\nimport {property, query, queryAssignedElements} from 'lit/decorators.js';\n\nimport {ARIAMixinStrict} from '../../internal/aria/aria.js';\nimport {mixinDelegatesAria} from '../../internal/aria/delegate.js';\nimport {\n FormSubmitter,\n setupFormSubmitter,\n type FormSubmitterType,\n} from '../../internal/controller/form-submitter.js';\nimport {\n dispatchActivationClick,\n isActivationClick,\n} from '../../internal/events/form-label-activation.js';\nimport {\n internals,\n mixinElementInternals,\n} from '../../labs/behaviors/element-internals.js';\n\n// Separate variable needed for closure.\nconst buttonBaseClass = mixinDelegatesAria(mixinElementInternals(LitElement));\n\n/**\n * A button component.\n */\nexport abstract class Button extends buttonBaseClass implements FormSubmitter {\n static {\n setupFormSubmitter(Button);\n }\n\n /** @nocollapse */\n static readonly formAssociated = true;\n\n /** @nocollapse */\n static override shadowRootOptions: ShadowRootInit = {\n mode: 'open',\n delegatesFocus: true,\n };\n\n /**\n * Whether or not the button is disabled.\n */\n @property({type: Boolean, reflect: true}) disabled = false;\n\n /**\n * Whether or not the button is \"soft-disabled\" (disabled but still\n * focusable).\n *\n * Use this when a button needs increased visibility when disabled. See\n * https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls\n * for more guidance on when this is needed.\n */\n @property({type: Boolean, attribute: 'soft-disabled', reflect: true})\n softDisabled = false;\n\n /**\n * The URL that the link button points to.\n */\n @property() href = '';\n\n /**\n * The filename to use when downloading the linked resource.\n * If not specified, the browser will determine a filename.\n * This is only applicable when the button is used as a link (`href` is set).\n */\n @property() download = '';\n\n /**\n * Where to display the linked `href` URL for a link button. Common options\n * include `_blank` to open in a new tab.\n */\n @property() target: '_blank' | '_parent' | '_self' | '_top' | '' = '';\n\n /**\n * Whether to render the icon at the inline end of the label rather than the\n * inline start.\n *\n * _Note:_ Link buttons cannot have trailing icons.\n */\n @property({type: Boolean, attribute: 'trailing-icon', reflect: true})\n trailingIcon = false;\n\n /**\n * Whether to display the icon or not.\n */\n @property({type: Boolean, attribute: 'has-icon', reflect: true}) hasIcon =\n false;\n\n /**\n * The default behavior of the button. May be \"button\", \"reset\", or \"submit\"\n * (default).\n */\n @property() type: FormSubmitterType = 'submit';\n\n /**\n * The value added to a form with the button's name when the button submits a\n * form.\n */\n @property({reflect: true}) value = '';\n\n get name() {\n return this.getAttribute('name') ?? '';\n }\n set name(name: string) {\n this.setAttribute('name', name);\n }\n\n /**\n * The associated form element with which this element's value will submit.\n */\n get form() {\n return this[internals].form;\n }\n\n @query('.button') private readonly buttonElement!: HTMLElement | null;\n\n @queryAssignedElements({slot: 'icon', flatten: true})\n private readonly assignedIcons!: HTMLElement[];\n\n constructor() {\n super();\n if (!isServer) {\n this.addEventListener('click', this.handleClick.bind(this));\n }\n }\n\n override focus() {\n this.buttonElement?.focus();\n }\n\n override blur() {\n this.buttonElement?.blur();\n }\n\n protected override render() {\n // Link buttons may not be disabled\n const isRippleDisabled = !this.href && (this.disabled || this.softDisabled);\n const buttonOrLink = this.href ? this.renderLink() : this.renderButton();\n // TODO(b/310046938): due to a limitation in focus ring/ripple, we can't use\n // the same ID for different elements, so we change the ID instead.\n const buttonId = this.href ? 'link' : 'button';\n return html`\n ${this.renderElevationOrOutline?.()}\n <div class=\"background\"></div>\n <md-focus-ring part=\"focus-ring\" for=${buttonId}></md-focus-ring>\n <md-ripple\n part=\"ripple\"\n for=${buttonId}\n ?disabled=\"${isRippleDisabled}\"></md-ripple>\n ${buttonOrLink}\n `;\n }\n\n // Buttons can override this to add elevation or an outline. Use this and\n // return `<md-elevation>` (for elevated, filled, and tonal buttons)\n // or `<div class=\"outline\">` (for outlined buttons).\n // Text buttons that have neither do not need to implement this.\n protected renderElevationOrOutline?(): unknown;\n\n private renderButton() {\n // Needed for closure conformance\n const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;\n return html`<button\n id=\"button\"\n class=\"button\"\n ?disabled=${this.disabled}\n aria-disabled=${this.softDisabled || nothing}\n aria-label=\"${ariaLabel || nothing}\"\n aria-haspopup=\"${ariaHasPopup || nothing}\"\n aria-expanded=\"${ariaExpanded || nothing}\">\n ${this.renderContent()}\n </button>`;\n }\n\n private renderLink() {\n // Needed for closure conformance\n const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;\n return html`<a\n id=\"link\"\n class=\"button\"\n aria-label=\"${ariaLabel || nothing}\"\n aria-haspopup=\"${ariaHasPopup || nothing}\"\n aria-expanded=\"${ariaExpanded || nothing}\"\n href=${this.href}\n download=${this.download || nothing}\n target=${this.target || nothing}\n >${this.renderContent()}\n </a>`;\n }\n\n private renderContent() {\n const icon = html`<slot\n name=\"icon\"\n @slotchange=\"${this.handleSlotChange}\"></slot>`;\n\n return html`\n <span class=\"touch\"></span>\n ${this.trailingIcon ? nothing : icon}\n <span class=\"label\"><slot></slot></span>\n ${this.trailingIcon ? icon : nothing}\n `;\n }\n\n private handleClick(event: MouseEvent) {\n // If the button is soft-disabled, we need to explicitly prevent the click\n // from propagating to other event listeners as well as prevent the default\n // action.\n if (!this.href && this.softDisabled) {\n event.stopImmediatePropagation();\n event.preventDefault();\n return;\n }\n\n if (!isActivationClick(event) || !this.buttonElement) {\n return;\n }\n this.focus();\n dispatchActivationClick(this.buttonElement);\n }\n\n private handleSlotChange() {\n this.hasIcon = this.assignedIcons.length > 0;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":"","sources":["button.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,8BAA8B,CAAC;AACtC,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAC,MAAM,KAAK,CAAC;AACxD,OAAO,EAAC,QAAQ,EAAE,KAAK,EAAE,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAGzE,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAEL,kBAAkB,GAEnB,MAAM,6CAA6C,CAAC;A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D,IAAI,EAAE,MAAM;IACZ,cAAc,EAAE,IAAI;CACrB,AAHgC,CAG/B;AAKwC;IAAzC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;wCAAkB;AAW3D;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;4CAChD;AAKT;IAAX,QAAQ,EAAE;oCAAW;AAOV;IAAX,QAAQ,EAAE;wCAAe;AAMd;IAAX,QAAQ,EAAE;sCAA2D;AAStE;IADC,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;4CAChD;AAK4C;IAAhE,QAAQ,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;uCACxD;AAMI;IAAX,QAAQ,EAAE;oCAAoC;AAMpB;IAA1B,QAAQ,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC;qCAAY;AAgBH;IAAlC,KAAK,CAAC,SAAS,CAAC;6CAAqD;AAGrD;IADhB,qBAAqB,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAC,CAAC;6CACN","sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport '../../focus/md-focus-ring.js';\nimport '../../ripple/ripple.js';\n\nimport {html, isServer, LitElement, nothing} from 'lit';\nimport {property, query, queryAssignedElements} from 'lit/decorators.js';\n\nimport {ARIAMixinStrict} from '../../internal/aria/aria.js';\nimport {mixinDelegatesAria} from '../../internal/aria/delegate.js';\nimport {\n FormSubmitter,\n setupFormSubmitter,\n type FormSubmitterType,\n} from '../../internal/controller/form-submitter.js';\nimport {\n dispatchActivationClick,\n isActivationClick,\n} from '../../internal/events/form-label-activation.js';\nimport {\n internals,\n mixinElementInternals,\n} from '../../labs/behaviors/element-internals.js';\n\n// Separate variable needed for closure.\nconst buttonBaseClass = mixinDelegatesAria(mixinElementInternals(LitElement));\n\n/**\n * A button component.\n */\nexport abstract class Button extends buttonBaseClass implements FormSubmitter {\n static {\n setupFormSubmitter(Button);\n }\n\n /** @nocollapse */\n static readonly formAssociated = true;\n\n /** @nocollapse */\n static override shadowRootOptions: ShadowRootInit = {\n mode: 'open',\n delegatesFocus: true,\n };\n\n /**\n * Whether or not the button is disabled.\n */\n @property({type: Boolean, reflect: true}) disabled = false;\n\n /**\n * Whether or not the button is \"soft-disabled\" (disabled but still\n * focusable).\n *\n * Use this when a button needs increased visibility when disabled. See\n * https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls\n * for more guidance on when this is needed.\n */\n @property({type: Boolean, attribute: 'soft-disabled', reflect: true})\n softDisabled = false;\n\n /**\n * The URL that the link button points to.\n */\n @property() href = '';\n\n /**\n * The filename to use when downloading the linked resource.\n * If not specified, the browser will determine a filename.\n * This is only applicable when the button is used as a link (`href` is set).\n */\n @property() download = '';\n\n /**\n * Where to display the linked `href` URL for a link button. Common options\n * include `_blank` to open in a new tab.\n */\n @property() target: '_blank' | '_parent' | '_self' | '_top' | '' = '';\n\n /**\n * Whether to render the icon at the inline end of the label rather than the\n * inline start.\n *\n * _Note:_ Link buttons cannot have trailing icons.\n */\n @property({type: Boolean, attribute: 'trailing-icon', reflect: true})\n trailingIcon = false;\n\n /**\n * Whether to display the icon or not.\n */\n @property({type: Boolean, attribute: 'has-icon', reflect: true}) hasIcon =\n false;\n\n /**\n * The default behavior of the button. May be \"button\", \"reset\", or \"submit\"\n * (default).\n */\n @property() type: FormSubmitterType = 'submit';\n\n /**\n * The value added to a form with the button's name when the button submits a\n * form.\n */\n @property({reflect: true}) value = '';\n\n get name() {\n return this.getAttribute('name') ?? '';\n }\n set name(name: string) {\n this.setAttribute('name', name);\n }\n\n /**\n * The associated form element with which this element's value will submit.\n */\n get form() {\n return this[internals].form;\n }\n\n @query('.button') private readonly buttonElement!: HTMLElement | null;\n\n @queryAssignedElements({slot: 'icon', flatten: true})\n private readonly assignedIcons!: HTMLElement[];\n\n constructor() {\n super();\n if (!isServer) {\n this.addEventListener('click', this.handleClick.bind(this));\n }\n }\n\n override focus() {\n this.buttonElement?.focus();\n }\n\n override blur() {\n this.buttonElement?.blur();\n }\n\n protected override render() {\n const isRippleDisabled = this.disabled || this.softDisabled;\n const buttonOrLink = this.href ? this.renderLink() : this.renderButton();\n // TODO(b/310046938): due to a limitation in focus ring/ripple, we can't use\n // the same ID for different elements, so we change the ID instead.\n const buttonId = this.href ? 'link' : 'button';\n return html`\n ${this.renderElevationOrOutline?.()}\n <div class=\"background\"></div>\n <md-focus-ring part=\"focus-ring\" for=${buttonId}></md-focus-ring>\n <md-ripple\n part=\"ripple\"\n for=${buttonId}\n ?disabled=\"${isRippleDisabled}\"></md-ripple>\n ${buttonOrLink}\n `;\n }\n\n // Buttons can override this to add elevation or an outline. Use this and\n // return `<md-elevation>` (for elevated, filled, and tonal buttons)\n // or `<div class=\"outline\">` (for outlined buttons).\n // Text buttons that have neither do not need to implement this.\n protected renderElevationOrOutline?(): unknown;\n\n private renderButton() {\n // Needed for closure conformance\n const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;\n return html`<button\n id=\"button\"\n class=\"button\"\n ?disabled=${this.disabled}\n aria-disabled=${this.softDisabled || nothing}\n aria-label=\"${ariaLabel || nothing}\"\n aria-haspopup=\"${ariaHasPopup || nothing}\"\n aria-expanded=\"${ariaExpanded || nothing}\">\n ${this.renderContent()}\n </button>`;\n }\n\n private renderLink() {\n // Needed for closure conformance\n const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;\n return html`<a\n id=\"link\"\n class=\"button\"\n aria-label=\"${ariaLabel || nothing}\"\n aria-haspopup=\"${ariaHasPopup || nothing}\"\n aria-expanded=\"${ariaExpanded || nothing}\"\n aria-disabled=${this.disabled || this.softDisabled || nothing}\n tabindex=\"${this.disabled && !this.softDisabled ? -1 : nothing}\"\n href=${this.href}\n download=${this.download || nothing}\n target=${this.target || nothing}\n >${this.renderContent()}\n </a>`;\n }\n\n private renderContent() {\n const icon = html`<slot\n name=\"icon\"\n @slotchange=\"${this.handleSlotChange}\"></slot>`;\n\n return html`\n <span class=\"touch\"></span>\n ${this.trailingIcon ? nothing : icon}\n <span class=\"label\"><slot></slot></span>\n ${this.trailingIcon ? icon : nothing}\n `;\n }\n\n private handleClick(event: MouseEvent) {\n // If the button is soft-disabled or a disabled link, we need to explicitly\n // prevent the click from propagating to other event listeners as well as\n // prevent the default action.\n if (this.softDisabled || (this.disabled && this.href)) {\n event.stopImmediatePropagation();\n event.preventDefault();\n return;\n }\n\n if (!isActivationClick(event) || !this.buttonElement) {\n return;\n }\n this.focus();\n dispatchActivationClick(this.buttonElement);\n }\n\n private handleSlotChange() {\n this.hasIcon = this.assignedIcons.length > 0;\n }\n}\n"]}
|