Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tab-nav): content clickable for screen readers #1692

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/components/src/components/tab-header/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
| ----------- | ------------ | ------------------------------------------------------------------------------------- | -------------------- | ----------- |
| `autoFocus` | `auto-focus` | (optional) autoFocus | `boolean` | `undefined` |
| `disabled` | `disabled` | True for a disabled Tabnavigation | `boolean` | `false` |
| `selected` | `selected` | | `boolean` | `undefined` |
| `selected` | `selected` | (optional) Whether the tab is selected | `boolean` | `undefined` |
| `size` | `size` | (optional) size | `"large" \| "small"` | `'small'` |
| `small` | `small` | <span style="color:red">**[DEPRECATED]**</span> - size should replace small<br/><br/> | `boolean` | `false` |
| `styles` | `styles` | (optional) Injected CSS styles | `string` | `undefined` |


## Events

| Event | Description | Type |
| -------------- | ----------- | ------------------ |
| `scale-select` | | `CustomEvent<any>` |


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
29 changes: 26 additions & 3 deletions packages/components/src/components/tab-header/tab-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { Component, h, Prop, Host, Watch, State, Element } from '@stencil/core';
import {
Component,
Element,
Event,
EventEmitter,
h,
Host,
Listen,
Prop,
State,
Watch,
} from '@stencil/core';
import classNames from 'classnames';
import { ScaleIcon, isScaleIcon } from '../../utils/utils';
import statusNote from '../../utils/status-note';
Expand All @@ -34,15 +45,27 @@ export class TabHeader {
/** @deprecated - size should replace small */
@Prop() small?: boolean = false;
/** (optional) size */
@Prop() size: 'small' | 'large' = 'small';
@Prop() size?: 'small' | 'large' = 'small';
/** (optional) autoFocus */
@Prop() autoFocus?: boolean;
/** (optional) Whether the tab is selected */
@Prop() selected?: boolean;
/** (optional) Injected CSS styles */
@Prop() styles?: string;
@Prop() selected: boolean;

@State() hasFocus: boolean = false;

@Event({ eventName: 'scale-select' }) scaleSelect: EventEmitter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we scope this event to avoid collisions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could, but I think it makes sense to also have this event be "public", no?


@Listen('click')
handleClick(event: MouseEvent) {
event.stopPropagation();
if (this.disabled) {
return;
}
this.scaleSelect.emit();
}

@Watch('selected')
selectedChanged(newValue: boolean) {
if (!this.hostElement.isConnected) {
Expand Down
33 changes: 6 additions & 27 deletions packages/components/src/components/tab-nav/tab-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,12 @@ export class TabNav {
/** (optional) Injected CSS styles */
@Prop() styles?: string;

@Listen('click')
handleClick(event: MouseEvent) {
// To provent event bubbling.
event.stopPropagation();

// workaround for slotted icons
const targetHTMLElement = event.target as HTMLElement;
const targetTag = targetHTMLElement.tagName.toLowerCase();
const svgTags = ['svg', 'g', 'path'];
let nextTab: HTMLScaleTabHeaderElement;

if (svgTags.includes(targetTag)) {
const closestNextTab = targetHTMLElement.closest(
`scale-tab-header[role="tab"]`
) as HTMLScaleTabHeaderElement;
if (closestNextTab) {
nextTab = closestNextTab;
this.selectTab(nextTab);
}
} else {
if (
(event.target as HTMLScaleTabHeaderElement).getAttribute('role') ===
'tab'
) {
nextTab = event.target as HTMLScaleTabHeaderElement;
this.selectTab(nextTab);
}
@Listen('scale-select')
handleSelect(event) {
const nextTab = event.target as HTMLScaleTabHeaderElement;
// Act only if it's a direct child
if (this.getAllEnabledTabs().includes(nextTab)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...or this takes care of collisions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this takes care of collisions with nested tabs… (an issue we had reported not long ago)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually with nested anything haha

this.selectTab(nextTab);
}
}

Expand Down