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(menu): improve keyboard accessibility on firefox #1529

Merged
merged 7 commits into from
Apr 22, 2024
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
6 changes: 6 additions & 0 deletions .changeset/large-kings-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rhds/elements": patch
---

`<rh-menu>`: improved focus accessibility for keyboard navigation users on firefox
`<rh-button>`: improved focus accessibility on firefox
7 changes: 7 additions & 0 deletions elements/rh-button/rh-button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LitElement, html, type TemplateResult } from 'lit';
import { customElement } from 'lit/decorators/custom-element.js';
import { property } from 'lit/decorators/property.js';
import { query } from 'lit/decorators/query.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';

Expand Down Expand Up @@ -48,6 +49,8 @@ export class RhButton extends LitElement {
/** Shorthand for the `icon` slot, the value is icon name */
@property() icon?: string;

@query('button') private _button!: HTMLButtonElement;

/**
* Changes the style of the button.
* - Primary: Used for the most important call to action on a page. Try to
Expand Down Expand Up @@ -150,6 +153,10 @@ export class RhButton extends LitElement {
return '';
}
}

focus() {
this._button?.focus();
}
}

declare global {
Expand Down
2 changes: 0 additions & 2 deletions elements/rh-menu/demo/color-context.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<rh-context-demo>
<rh-menu>
<rh-button>Toggle Links</rh-button>
<a href="#">Link1</a>
<a href="#">Link2</a>
<a href="#">Link3</a>
Expand All @@ -13,4 +12,3 @@
import '@rhds/elements/rh-button/rh-button.js';
import '@rhds/elements/lib/elements/rh-context-demo/rh-context-demo.js';
</script>

1 change: 0 additions & 1 deletion elements/rh-menu/demo/position-left.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<rh-menu position="left" persistent>
<rh-button slot="button">Toggle Settings</rh-button>
<rh-button variant="link">Menuitem1</rh-button>
<rh-button variant="link">Menuitem2</rh-button>
<rh-button variant="link">Menuitem3</rh-button>
Expand Down
1 change: 0 additions & 1 deletion elements/rh-menu/demo/position-right.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<rh-menu position="right">
<rh-button slot="button">Toggle Links</rh-button>
<a href="#">Link1</a>
<a href="#">Link2</a>
<a href="#">Link3</a>
Expand Down
1 change: 0 additions & 1 deletion elements/rh-menu/demo/position-top.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<rh-menu position="top">
<rh-button slot="button">Toggle Menu</rh-button>
<rh-button variant="link">Menuitem1</rh-button>
<rh-button variant="link">Menuitem2</rh-button>
<rh-button variant="link">Menuitem3</rh-button>
Expand Down
1 change: 0 additions & 1 deletion elements/rh-menu/demo/rh-menu.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<rh-menu id="rh-buttons">
<rh-button slot="button">Toggle Menu</rh-button>
<rh-button data-item="1" variant="link">Menuitem1</rh-button>
<rh-button data-item="2" variant="link">Menuitem2</rh-button>
<rh-button data-item="3" variant="link">Menuitem3</rh-button>
Expand Down
5 changes: 4 additions & 1 deletion elements/rh-menu/rh-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ slot {
width: max-content;
}

::slotted(a) {
padding: 5px !important; /* WARNING: not a token value */
}

.dark::slotted(a) {
color: var(--rh-color-interactive-blue-lightest, #b9dafc) !important;
padding: 5px !important; /* WARNING: not a token value */
}

.dark::slotted(a:hover) {
Expand Down
6 changes: 6 additions & 0 deletions elements/rh-menu/rh-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class MenuToggleEvent extends Event {
export class RhMenu extends LitElement {
static readonly styles = [styles];

static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };

@queryAssignedElements() private _menuItems!: HTMLElement[];

@colorContextConsumer() private on?: ColorTheme;
Expand Down Expand Up @@ -64,6 +66,10 @@ export class RhMenu extends LitElement {
activateItem(item: HTMLElement) {
this.#tabindex.setActiveItem(item);
}

focus() {
this.#tabindex.activeItem?.focus();
}
}

declare global {
Expand Down
Loading