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(ui-source-code-editor): link label to input field programmatically #1865

Conversation

ToMESSKa
Copy link
Contributor

@ToMESSKa ToMESSKa commented Feb 7, 2025

Closes: INSTUI-4289

ISSUE: SourceCodeEditor label is not linked to the input field pragmatically. Therefore screenreader does not read the label when tabbed into the input field

TEST PLAN:

  • open the first example in SourceCodeEditor
  • with a screenreader go into the input field
  • the screenreader should announce the label 'javascript SourceCodeEditor with syntax highlight" when entering the input field
  • the input (textbox) element should have an "aria-labelledby" attribute pointing to the label element by id.

Copy link

github-actions bot commented Feb 7, 2025

PR Preview Action v1.6.0
Preview removed because the pull request was closed.
2025-02-11 08:33 UTC

@@ -655,7 +665,7 @@ class SourceCodeEditor extends Component<SourceCodeEditorProps> {
omitProps(restProps, SourceCodeEditor.allowedProps)
)}
>
<label css={styles?.label} htmlFor={this._id}>
<label css={styles?.label} id={this._id}>
Copy link
Contributor Author

@ToMESSKa ToMESSKa Feb 7, 2025

Choose a reason for hiding this comment

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

htmlFor does not work for div elements and the textbox is a div element in CodeMirror so replaced with id

@ToMESSKa ToMESSKa self-assigned this Feb 7, 2025
@ToMESSKa ToMESSKa changed the title fix(ui-sourcecodeeditor): link label to input field programmatically fix(ui-source-code-editor): link label to input field programmatically Feb 7, 2025
@@ -644,6 +645,15 @@ class SourceCodeEditor extends Component<SourceCodeEditorProps> {
}
}

assignAriaLabel = () => {
if (this._containerRef) {
const editorDiv = this._containerRef.querySelector('[role="textbox"]')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because the CodeMirror does not provide any way to reach this element, I had to find it like this

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative way to find textbox is to go through child elements of the containerRef if it is an element but this is good as well.

Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

nice work :)

@ToMESSKa ToMESSKa merged commit b092b45 into master Feb 11, 2025
11 checks passed
@ToMESSKa ToMESSKa deleted the INSTUI-4289_source_code_editor_provide_visual_labels_for_the_souce_code_editor_example_in_the_docs branch February 11, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants