Skip to content

Commit

Permalink
fix(button): closure conformance issue
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 526720124
  • Loading branch information
asyncLiz authored and copybara-github committed Apr 24, 2023
1 parent 0a35ff5 commit 9e23477
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
9 changes: 6 additions & 3 deletions button/lib/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {dispatchActivationClick, isActivationClick} from '../../controller/event
import {pointerPress, shouldShowStrongFocus} from '../../focus/strong-focus.js';
import {ripple} from '../../ripple/directive.js';
import {MdRipple} from '../../ripple/ripple.js';
import {ARIAMixinStrict} from '../../types/aria.js';

/**
* A button component.
Expand Down Expand Up @@ -118,13 +119,15 @@ export abstract class Button extends LitElement {
const isDisabled = this.disabled && !this.href;

const button = this.href ? literal`a` : literal`button`;
// Needed for closure conformance
const {ariaLabel, ariaHasPopup, ariaExpanded} = this as ARIAMixinStrict;
return staticHtml`
<${button}
class="md3-button ${classMap(this.getRenderClasses())}"
?disabled=${isDisabled}
aria-label="${this.ariaLabel || nothing}"
aria-haspopup="${this.ariaHasPopup || nothing}"
aria-expanded="${this.ariaExpanded || nothing}"
aria-label="${ariaLabel || nothing}"
aria-haspopup="${ariaHasPopup || nothing}"
aria-expanded="${ariaExpanded || nothing}"
href=${this.href || nothing}
target=${this.target || nothing}
@pointerdown="${this.handlePointerDown}"
Expand Down
62 changes: 61 additions & 1 deletion types/aria.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,72 @@
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*
*/
/**
* @fileoverview Provides types for `ariaX` properties. These are required when
* typing `ariaX` properties since lit analyzer requires strict aria string
* types.
*/

/**
* An extension of `ARIAMixin` that enforces strict value types for aria
* properties.
*
* This is needed for correct typing in render functions with lit analyzer.
*
* @example
* render() {
* const {ariaLabel} = this as ARIAMixinStrict;
* return html`
* <button aria-label=${ariaLabel || nothing}>
* <slot></slot>
* </button>
* `;
* }
*/
export interface ARIAMixinStrict extends ARIAMixin {
ariaAtomic: 'true'|'false'|null;
ariaAutoComplete: 'none'|'inline'|'list'|'both'|null;
ariaBusy: 'true'|'false'|null;
ariaChecked: 'true'|'false'|null;
ariaColCount: `${number}`|null;
ariaColIndex: `${number}`|null;
ariaColIndexText: string|null;
ariaColSpan: `${number}`|null;
ariaCurrent: 'page'|'step'|'location'|'date'|'time'|'true'|'false'|null;
ariaDisabled: 'true'|'false'|null;
ariaExpanded: 'true'|'false'|null;
ariaHasPopup: 'false'|'true'|'menu'|'listbox'|'tree'|'grid'|'dialog'|null;
ariaHidden: 'true'|'false'|null;
ariaInvalid: 'true'|'false'|null;
ariaKeyShortcuts: string|null;
ariaLabel: string|null;
ariaLevel: `${number}`|null;
ariaLive: 'assertive'|'off'|'polite'|null;
ariaModal: 'true'|'false'|null;
ariaMultiLine: 'true'|'false'|null;
ariaMultiSelectable: 'true'|'false'|null;
ariaOrientation: 'horizontal'|'vertical'|'undefined'|null;
ariaPlaceholder: string|null;
ariaPosInSet: `${number}`|null;
ariaPressed: 'true'|'false'|null;
ariaReadOnly: 'true'|'false'|null;
ariaRequired: 'true'|'false'|null;
ariaRoleDescription: string|null;
ariaRowCount: `${number}`|null;
ariaRowIndex: `${number}`|null;
ariaRowIndexText: string|null;
ariaRowSpan: `${number}`|null;
ariaSelected: 'true'|'false'|null;
ariaSetSize: `${number}`|null;
ariaSort: 'ascending'|'descending'|'none'|'other'|null;
ariaValueMax: `${number}`|null;
ariaValueMin: `${number}`|null;
ariaValueNow: `${number}`|null;
ariaValueText: string|null;
role: ARIARole|null;
}

/**
* Valid values for `aria-expanded`.
*/
Expand Down

0 comments on commit 9e23477

Please sign in to comment.