buildCodeEditorContentAttributes()
function buildCodeEditorContentAttributes(state): Record<string, string>;
Defined in: accessibility.ts:61
把无障碍状态转换成 EditorView.contentAttributes 的属性字典。
Parameters
| Parameter | Type | Description |
|---|---|---|
state | CodeEditorAccessibilityState | 当前的无障碍状态 |
Returns
Record<string, string>
只包含确有取值的属性;没有任何取值时返回空对象
Remarks
空串一律不产出属性,而不是产出一个空属性:aria-label="" 会让 textbox
从「没有可访问名称」变成「可访问名称是空字符串」,某些屏幕阅读器就此不再回退到
aria-labelledby 或周边文本,可访问性反而更差。
aria-disabled 只在禁用时出现。写 aria-disabled="false" 是合法的,但它与
CodeMirror 自己写出的 aria-readonly 叠在一起会让「只读」与「禁用」两种状态
更难区分,因此未禁用时直接不写。
返回的是新对象,可以直接交给 EditorView.contentAttributes.of(...)。
CodeMirror 会把上一次的属性与本次做差量,多余的属性由它负责移除。
Example
const attributes = buildCodeEditorContentAttributes({ disabled: true, label: '代码输入' });
// `{ 'aria-disabled': 'true', 'aria-label': '代码输入' }`
view.dispatch({ effects: a11yConf.reconfigure(EditorView.contentAttributes.of(attributes)) });