From dfc87f32e8621b0bbcf8156a276bd67a5ecd1ddc Mon Sep 17 00:00:00 2001 From: Elizabeth Mitchell Date: Thu, 24 Aug 2023 16:43:44 -0700 Subject: [PATCH] fix(chips): linear navigation not working in VoiceOver A lot of the changes are in order to fix filter chips with VoiceOver. With the extra divs and no aria-hidden on ripple/focus ring, VoiceOver got stuck on the first filter chip with linear navigation. Elevated link chips also got their border changed to white instead of yellow in HCM to match Wiz. PiperOrigin-RevId: 559908582 --- chips/demo/stories.ts | 6 +- chips/internal/_elevated.scss | 4 -- chips/internal/assist-chip.ts | 20 +++--- chips/internal/chip.ts | 78 ++++++++++++++---------- chips/internal/filter-chip.ts | 28 ++++----- chips/internal/input-chip.ts | 29 +++++---- chips/internal/multi-action-chip.ts | 10 +-- chips/internal/multi-action-chip_test.ts | 6 +- 8 files changed, 99 insertions(+), 82 deletions(-) diff --git a/chips/demo/stories.ts b/chips/demo/stories.ts index b9252f88d0..3b5e5020e2 100644 --- a/chips/demo/stories.ts +++ b/chips/demo/stories.ts @@ -62,7 +62,7 @@ const standard: MaterialStoryInit = { ?disabled=${disabled} ?elevated=${elevated} > - + local_laundry_service `; @@ -108,7 +108,7 @@ const filters: MaterialStoryInit = { ?disabled=${disabled} ?elevated=${elevated} > - + local_laundry_service = { ?disabled=${disabled} ?elevated=${elevated} > - + local_laundry_service `; diff --git a/chips/internal/_elevated.scss b/chips/internal/_elevated.scss index 0d413543f2..751107a564 100644 --- a/chips/internal/_elevated.scss +++ b/chips/internal/_elevated.scss @@ -63,10 +63,6 @@ border: 1px solid CanvasText; } - .elevated.link md-elevation { - border-color: ActiveText; - } - .elevated.disabled md-elevation { border-color: GrayText; } diff --git a/chips/internal/assist-chip.ts b/chips/internal/assist-chip.ts index de6f5ac211..014baabc09 100644 --- a/chips/internal/assist-chip.ts +++ b/chips/internal/assist-chip.ts @@ -11,7 +11,7 @@ import {property} from 'lit/decorators.js'; import {ARIAMixinStrict} from '../../internal/aria/aria.js'; -import {Chip} from './chip.js'; +import {Chip, renderGridAction, renderGridContainer} from './chip.js'; /** * An assist chip component. @@ -30,6 +30,10 @@ export class AssistChip extends Chip { return !this.href && this.disabled; } + protected override renderContainer(content: unknown) { + return renderGridContainer(content, this.getContainerClasses()); + } + protected override getContainerClasses() { return { ...super.getContainerClasses(), @@ -40,27 +44,27 @@ export class AssistChip extends Chip { }; } - protected override renderAction() { + protected override renderPrimaryAction(content: unknown) { const {ariaLabel} = this as ARIAMixinStrict; if (this.href) { - return html` + return renderGridAction(html` ${this.renderContent()} - `; + >${content} + `); } - return html` + return renderGridAction(html` - `; + >${content} + `); } protected override renderOutline() { diff --git a/chips/internal/chip.ts b/chips/internal/chip.ts index aff6095ec6..088549869a 100644 --- a/chips/internal/chip.ts +++ b/chips/internal/chip.ts @@ -8,8 +8,8 @@ import '../../focus/md-focus-ring.js'; import '../../ripple/ripple.js'; import {html, LitElement, nothing, TemplateResult} from 'lit'; -import {property, state} from 'lit/decorators.js'; -import {classMap} from 'lit/directives/class-map.js'; +import {property} from 'lit/decorators.js'; +import {ClassInfo, classMap} from 'lit/directives/class-map.js'; import {requestUpdateOnAriaChange} from '../../internal/aria/delegate.js'; @@ -43,47 +43,43 @@ export abstract class Chip extends LitElement { return this.disabled; } - /** - * The aria role of the container. Defaults to `row` for grid chip sets. - * Listbox chip sets should remove this since they do not contain cells. - */ - @state() protected containerRole?: 'row' = 'row'; - protected override render() { - return html` -
- ${this.renderOutline()} - - - ${this.renderActions()} -
- `; + return this.renderContainer(this.renderContainerContent()); } + protected abstract renderContainer(content: unknown): unknown; + protected getContainerClasses() { return { disabled: this.disabled, }; } - protected renderActions() { - return this.renderActionCell(this.renderAction()); + protected renderContainerContent() { + // Note: add aria-hidden="true" to focus ring and ripple. For some reason + // they cause VoiceOver to get stuck inside filter chip sets without it. + // TODO(b/297428579): investigate and file VoiceOver bug + return html` + ${this.renderOutline()} + + + ${this.renderPrimaryAction(this.renderPrimaryContent())} + `; } - protected renderActionCell(content: TemplateResult| - typeof nothing): TemplateResult|typeof nothing { - if (content === nothing) { - return content; - } + protected renderOutline() { + return html``; + } - return html`
${content}
`; + protected renderLeadingIcon(): TemplateResult { + return html``; } - protected abstract renderAction(): TemplateResult; + protected abstract renderPrimaryAction(content: unknown): unknown; - protected renderContent() { + private renderPrimaryContent() { return html`