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 a accessibility issue to allow screenreader to read a label when … #6197

Merged
merged 4 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ <h2>Configuration</h2>
simply <code>true</code>), focusing of the editor is also
disallowed.</dd>

<dt id="option_srLabel"><code><strong>srLabel</strong>: string</code></dt>
<dd>This label is read by the screenreaders when CodeMirror text area is focussed. This
Copy link
Member

Choose a reason for hiding this comment

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

It's "focused" (one s)

is helpful for accessibility.</dd>

<dt id="option_showCursorWhenSelecting"><code><strong>showCursorWhenSelecting</strong>: boolean</code></dt>
<dd>Whether the cursor should be drawn when a selection is
active. Defaults to false.</dd>
Expand Down
1 change: 1 addition & 0 deletions src/edit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export function defineOptions(CodeMirror) {
}
cm.display.input.readOnlyChanged(val)
})
option("srLabel", 'CodeMirror text input')
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer to call this option either just label or screenReaderLabel. The abbreviation seems unnecessary.

option("disableInput", false, (cm, val) => {if (!val) cm.display.input.reset()}, true)
option("dragDrop", true, dragDropChanged)
option("allowDropFileTypes", null)
Expand Down
2 changes: 1 addition & 1 deletion src/input/TextareaInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class TextareaInput {

createField(_display) {
// Wraps and hides input textarea
this.wrapper = hiddenTextarea()
this.wrapper = hiddenTextarea(this.cm.options.srLabel)
// The semihidden textarea that is focused when the editor is
// focused, and receives input.
this.textarea = this.wrapper.firstChild
Expand Down
10 changes: 8 additions & 2 deletions src/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ export function disableBrowserMagic(field, spellcheck, autocorrect, autocapitali
field.setAttribute("spellcheck", !!spellcheck)
}

export function hiddenTextarea() {
export function hiddenTextarea(label) {
let te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none")
let div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;")
let te_id = 'cm-textarea-' + Math.floor(Math.random() * 9999)
te.setAttribute('id', te_id)
/* Label for screenreaders, accessibility */
let le = elt("label", label, null, 'position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;')
le.setAttribute('for', te_id)
Copy link
Member

Choose a reason for hiding this comment

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

Why aren't you using an aria-label attribute directly on the textarea?


let div = elt("div", [te, le], null, "overflow: hidden; position: relative; width: 3px; height: 0px;")
// The textarea is kept positioned near the cursor to prevent the
// fact that it'll be scrolled into view on input from scrolling
// our fake cursor out of view. On webkit, when wrap=off, paste is
Expand Down