-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Descriptive aria-labels for Keyboard shortcuts which include punctuation previously ignored by screen readers #666
base: main
Are you sure you want to change the base?
Changes from 7 commits
8277c16
37881ea
8a3cd15
ad4e98d
e759582
a466334
cffd4aa
ebc9057
0da3605
3e72e0e
4f99e9c
3a1ac15
6a8f2e0
5406474
a747e97
f013646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1221,7 +1221,14 @@ export namespace Menu { | |
*/ | ||
renderShortcut(data: IRenderData): VirtualElement { | ||
let content = this.formatShortcut(data); | ||
return h.div({ className: 'lm-Menu-itemShortcut' }, content); | ||
let ariaContent = this.formatShortcutText(data); | ||
return h.div( | ||
{ | ||
className: 'lm-Menu-itemShortcut', | ||
'aria-label': `${ariaContent}` | ||
}, | ||
content | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -1371,6 +1378,41 @@ export namespace Menu { | |
let kb = data.item.keyBinding; | ||
return kb ? CommandRegistry.formatKeystroke(kb.keys) : null; | ||
} | ||
|
||
/** | ||
* @returns The aria label content to add to the shortcut node. | ||
*/ | ||
formatShortcutText(data: IRenderData): h.Child { | ||
const keyToText: { [key: string]: string } = { | ||
']': 'Closing bracket', | ||
'[': 'Opening bracket', | ||
',': 'Comma', | ||
'.': 'Full stop', | ||
"'": 'Single quote', | ||
'-': 'Hyphen-minus' | ||
}; | ||
|
||
let kbText = data.item.keyBinding; | ||
let result = kbText ? CommandRegistry.formatKeystroke(kbText.keys) : null; | ||
|
||
let punctuationRegex = /\p{P}/u; | ||
let punctuations = result?.match(punctuationRegex); | ||
if (!punctuations) { | ||
return []; | ||
} | ||
for (const punctuation of punctuations) { | ||
if (result != null && Object.keys(keyToText).includes(punctuation)) { | ||
const individualKeys = result.split('+'); | ||
let index = individualKeys.indexOf(punctuation); | ||
if (index != -1) { | ||
individualKeys[index] = keyToText[punctuation]; | ||
} | ||
const textShortcut = individualKeys.join('+'); | ||
return textShortcut; | ||
} | ||
} | ||
return kbText ? CommandRegistry.formatKeystroke(kbText.keys) : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All right, this makes it pretty clear that we need to have this implemented at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @krassowski, All makes sense, thank you for your comments. I will revert back to draft for now whist I work on these and let you know once ready for review again. |
||
} | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we would want to make it easy to override in subclasses of the renderer so that they could reuse the logic below, but change the values on the right-hand side. In particular, JupyterLab will want to substituted the values with translated versions.
One solution would be making
keyToText
an option that can be passed to the renderer constructor, something like:But please read the next comment which tackles the deeper question on where the logic should be placed before implementing the suggestion above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@krassowski I had tried to use aria-keyshortcuts in place of aria-label however, my screen reader (Windows Narrator) still omits some punctuation. With aria-label it is read out as expected.
I have implemented your other suggestions which should now allow translations to be substituted in JupyterLab