diff --git a/iconbutton/icon-button_test.ts b/iconbutton/icon-button_test.ts index 461aa43708..8054c3d5b4 100644 --- a/iconbutton/icon-button_test.ts +++ b/iconbutton/icon-button_test.ts @@ -146,8 +146,8 @@ describe('icon button tests', () => { throw new Error( 'Icon button is not instance of MdStandardIconButtonToggle.'); } - element.ariaLabelOn = 'aria label on'; - element.ariaLabelOff = 'aria label off'; + element.ariaLabelSelected = 'aria label on'; + element.ariaLabel = 'aria label off'; await element.updateComplete; const button = element.shadowRoot!.querySelector('button')!; diff --git a/iconbutton/lib/icon-button-toggle.ts b/iconbutton/lib/icon-button-toggle.ts index 3f527ca395..3d746fbcd8 100644 --- a/iconbutton/lib/icon-button-toggle.ts +++ b/iconbutton/lib/icon-button-toggle.ts @@ -11,40 +11,24 @@ import '../../focus/focus-ring.js'; import '../../icon/icon.js'; import '../../ripple/ripple.js'; -import {html, LitElement, nothing, TemplateResult} from 'lit'; -import {property, queryAsync, state} from 'lit/decorators.js'; +import {html, nothing, TemplateResult} from 'lit'; +import {property} from 'lit/decorators.js'; import {ClassInfo, classMap} from 'lit/directives/class-map.js'; import {when} from 'lit/directives/when.js'; -import {ariaProperty} from '../../decorators/aria-property.js'; -import {pointerPress, shouldShowStrongFocus} from '../../focus/strong-focus.js'; import {ripple} from '../../ripple/directive.js'; -import {MdRipple} from '../../ripple/ripple.js'; + +import {IconButton} from './icon-button.js'; /** * @fires icon-button-toggle-change {CustomEvent<{selected: boolean}>} * Dispatched whenever `selected` is changed via user click */ -export class IconButtonToggle extends LitElement { - @ariaProperty - @property({type: String, attribute: 'data-aria-label'}) - override ariaLabel!: string; - - /** - * Disables the icon button and makes it non-interactive. - */ - @property({type: Boolean, reflect: true}) disabled = false; - +export class IconButtonToggle extends IconButton { /** * The `aria-label` of the button when the toggle button is selected or "on". */ - @property({type: String}) ariaLabelOn!: string; - - /** - * The `aria-label` of the button when the toggle button is not selected or - * "off". - */ - @property({type: String}) ariaLabelOff!: string; + @property({type: String}) ariaLabelSelected!: string; /** * Sets the toggle button to the "on" state and displays the `onIcon`. If @@ -53,26 +37,11 @@ export class IconButtonToggle extends LitElement { */ @property({type: Boolean, reflect: true}) selected = false; - @queryAsync('md-ripple') ripple!: Promise; - - @state() protected showFocusRing = false; - - @state() protected showRipple = false; - - protected readonly getRipple = () => { - this.showRipple = true; - return this.ripple; - }; - - protected readonly renderRipple = () => { - return html``; - }; - protected override render(): TemplateResult { - const hasToggledAriaLabel = this.ariaLabelOn && this.ariaLabelOff; + const hasToggledAriaLabel = this.ariaLabel && this.ariaLabelSelected; const ariaPressedValue = hasToggledAriaLabel ? nothing : this.selected; - const ariaLabelValue = hasToggledAriaLabel ? - (this.selected ? this.ariaLabelOn : this.ariaLabelOff) : + const ariaLabelValue = (hasToggledAriaLabel && this.selected) ? + this.ariaLabelSelected : this.ariaLabel; return html``; } - protected getRenderClasses(): ClassInfo { + protected renderSelectedIcon() { + return html``; + } + + protected override getRenderClasses(): ClassInfo { return { + ...super.getRenderClasses(), 'md3-icon-button--on': this.selected, }; } - protected renderTouchTarget() { - return html``; - } - - protected renderFocusRing() { - return html``; - } - - protected handlePointerDown(e: PointerEvent) { - pointerPress(); - this.showFocusRing = shouldShowStrongFocus(); - } - - protected handleFocus() { - this.showFocusRing = shouldShowStrongFocus(); - } - - protected handleBlur() { - this.showFocusRing = false; - } - protected handleClick() { this.selected = !this.selected; const detail = {selected: this.selected}; diff --git a/iconbutton/lib/icon-button.ts b/iconbutton/lib/icon-button.ts index 5426cc45a2..7a714041b0 100644 --- a/iconbutton/lib/icon-button.ts +++ b/iconbutton/lib/icon-button.ts @@ -26,6 +26,9 @@ import {ARIAHasPopup} from '../../types/aria.js'; // tslint:disable-next-line:enforce-comments-on-exported-symbols export class IconButton extends LitElement { + /** + * Disables the icon button and makes it non-interactive. + */ @property({type: Boolean, reflect: true}) disabled = false; /**