Elizabeth Mitchell 5df9410e60 fix!: aria-labels announcing twice with "group" on components
BREAKING CHANGE: `querySelector` for `[role]` and `[aria-*]` attributes may no longer work. See `@material/web/migrations/v2/README.md` and `@material/web/migrations/v2/query-selector-aria.ts`.

Browser/SR test results (go/mwc-double-aria-test-results)
  -  VoiceOver on Chrome
  -  VoiceOver on iOS Safari
  -  TalkBack on Chrome
  -  ChromeVox on Chrome
  -  NVDA on Chrome
  -  NVDA on Firefox
  -  JAWS on Chrome
  -  JAWS on Firefox
  (Optional)
  -  VoiceOver on Safari
  -  VoiceOver on Firefox

PiperOrigin-RevId: 648859827
2024-07-02 15:22:12 -07:00

67 lines
1.8 KiB
TypeScript

/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {html, LitElement, nothing, TemplateResult} from 'lit';
import {property} from 'lit/decorators.js';
import {classMap} from 'lit/directives/class-map.js';
import {ARIAMixinStrict} from '../../internal/aria/aria.js';
import {mixinDelegatesAria} from '../../internal/aria/delegate.js';
// Separate variable needed for closure.
const progressBaseClass = mixinDelegatesAria(LitElement);
/**
* A progress component.
*/
export abstract class Progress extends progressBaseClass {
/**
* Progress to display, a fraction between 0 and `max`.
*/
@property({type: Number}) value = 0;
/**
* Maximum progress to display, defaults to 1.
*/
@property({type: Number}) max = 1;
/**
* Whether or not to display indeterminate progress, which gives no indication
* to how long an activity will take.
*/
@property({type: Boolean}) indeterminate = false;
/**
* Whether or not to render indeterminate mode using 4 colors instead of one.
*/
@property({type: Boolean, attribute: 'four-color'}) fourColor = false;
protected override render() {
// Needed for closure conformance
const {ariaLabel} = this as ARIAMixinStrict;
return html`
<div
class="progress ${classMap(this.getRenderClasses())}"
role="progressbar"
aria-label="${ariaLabel || nothing}"
aria-valuemin="0"
aria-valuemax=${this.max}
aria-valuenow=${this.indeterminate ? nothing : this.value}
>${this.renderIndicator()}</div
>
`;
}
protected getRenderClasses() {
return {
'indeterminate': this.indeterminate,
'four-color': this.fourColor,
};
}
protected abstract renderIndicator(): TemplateResult;
}