-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add accessibility props to action_button (#248)
- Also fix how the name is retrieved from the element, and include the event type on keyboard events - Tested using the examples added
- Loading branch information
Showing
11 changed files
with
166 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
plugins/ui/src/deephaven/ui/components/spectrum/accessibility.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from __future__ import annotations | ||
from typing import Literal, Union | ||
|
||
# Accessibility typings | ||
|
||
BoolLiteral = Union[Literal["true", "false"], bool] | ||
AriaExpanded = BoolLiteral | ||
AriaHasPopup = Union[BoolLiteral, Literal["menu", "listbox", "tree", "grid", "dialog"]] | ||
AriaPressed = Union[BoolLiteral, Literal["mixed"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getTargetName } from './EventUtils'; | ||
|
||
describe('getTargetName', () => { | ||
it('should return the name attribute if it exists', () => { | ||
const target = document.createElement('div'); | ||
target.setAttribute('name', 'test-name'); | ||
expect(getTargetName(target)).toBe('test-name'); | ||
}); | ||
|
||
it('should return the name if both name and id exist', () => { | ||
const target = document.createElement('div'); | ||
target.setAttribute('name', 'test-name'); | ||
target.setAttribute('id', 'test-id'); | ||
expect(getTargetName(target)).toBe('test-name'); | ||
}); | ||
|
||
it('should return the id attribute if the name attribute does not exist', () => { | ||
const target = document.createElement('div'); | ||
target.setAttribute('id', 'test-id'); | ||
expect(getTargetName(target)).toBe('test-id'); | ||
}); | ||
|
||
it('should return undefined if neither the name nor id attribute exists', () => { | ||
const target = document.createElement('div'); | ||
expect(getTargetName(target)).toBeUndefined(); | ||
}); | ||
|
||
it('should return undefined if the target is null', () => { | ||
expect(getTargetName(null)).toBeUndefined(); | ||
}); | ||
|
||
it('should return undefined if the target is not an Element', () => { | ||
const target = {} as EventTarget; | ||
expect(getTargetName(target)).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function getTargetName(target: EventTarget | null): string | undefined { | ||
if (target instanceof Element) { | ||
return ( | ||
target.getAttribute('name') ?? target.getAttribute('id') ?? undefined | ||
); | ||
} | ||
return undefined; | ||
} | ||
|
||
export default getTargetName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters