accessbility improvements for issue #109

the bold, italic and strikethrough options now function as toggles for
formatting options and removes them rather than just replacing text

the options buttons under the meta ui now communicate their status
through use of the 'aria pressed' attribute so they can be properly read
by assitive technologies like screen readers
This commit is contained in:
RXP 2025-05-13 10:58:21 -06:00
parent 714485c6a6
commit 6c44f58448
Signed by: ro
GPG key ID: 976711B5057688B7
3 changed files with 50 additions and 22 deletions

View file

@ -167,9 +167,13 @@ export default class PostEditor {
}
if (currentOption != null) {
let active = currentOption.getAttribute('data-active');
active == 'false'
? currentOption.setAttribute('data-active', 'true')
: currentOption.setAttribute('data-active', 'false');
if (active == 'false') {
currentOption.setAttribute('data-active', 'true');
currentOption.setAttribute('aria-pressed', 'true');
} else {
currentOption.setAttribute('data-active', 'false');
currentOption.setAttribute('aria-pressed', 'false');
}
}
}
handleEditorOptions(e) {

View file

@ -124,30 +124,54 @@ class TextEditor extends EventEmitter {
let end = this.textEditor.selectionEnd;
let selectedText = this.textEditor.value.substring(start, end);
let formatText = this.textEditor.value.substring(start - 1, end + 1);
let insert = '';
switch (e.target.id) {
case 'edit-bold':
insert = '**' + selectedText + '**';
this.textEditor.value =
this.textEditor.value.substring(0, start) +
insert +
this.textEditor.value.substring(end, len);
if (formatText.includes('*')) {
insert = selectedText;
this.textEditor.value =
this.textEditor.value.substring(0, start - 2) +
insert +
this.textEditor.value.substring(end + 2, len);
} else {
insert = '**' + selectedText + '**';
this.textEditor.value =
this.textEditor.value.substring(0, start) +
insert +
this.textEditor.value.substring(end, len);
}
break;
case 'edit-italic':
insert = '*' + selectedText + '*';
//console.log(this.textEditor);
this.textEditor.value =
this.textEditor.value.substring(0, start) +
insert +
this.textEditor.value.substring(end, len);
if (formatText.includes('*')) {
insert = selectedText;
this.textEditor.value =
this.textEditor.value.substring(0, start - 1) +
insert +
this.textEditor.value.substring(end + 1, len);
} else {
insert = '*' + selectedText + '*';
this.textEditor.value =
this.textEditor.value.substring(0, start) +
insert +
this.textEditor.value.substring(end, len);
}
break;
case 'edit-strikethrough':
insert = '~~' + selectedText + '~~';
this.textEditor.value =
this.textEditor.value.substring(0, start) +
insert +
this.textEditor.value.substring(end, len);
if (formatText.includes('~')) {
insert = selectedText;
this.textEditor.value =
this.textEditor.value.substring(0, start - 2) +
insert +
this.textEditor.value.substring(end + 2, len);
} else {
insert = '~~' + selectedText + '~~';
this.textEditor.value =
this.textEditor.value.substring(0, start) +
insert +
this.textEditor.value.substring(end, len);
}
break;
case 'edit-header1':
insert = '# ' + selectedText + '\n';

View file

@ -30,15 +30,15 @@ if(isset($page['uuid']))
?>
<div role="toolbar" aria-label="page options" aria-orientation="horizontal">
<button id="option-menu-pin" class="option-inactive post-option-btn" data-active="{{$menu}}" title='Pin to Menu' aria-label="pin to menu">
<button id="option-menu-pin" class="option-inactive post-option-btn" aria-pressed="{{$menu}}" data-active="{{$menu}}" title='Pin to Menu' aria-label="pin to menu">
<svg id="option-menu-pin" class="icon">
<use id="option-menu-pin" xlink:href="/assets/images/global/sprite.svg#entypo-pin" />
</svg>
</button><button id="option-feature" class="option-inactive post-option-btn" data-active="{{$featured}}" title='Feature' aria-label="feature post toggle">
</button><button id="option-feature" class="option-inactive post-option-btn" aria-pressed="{{$featured}}" data-active="{{$featured}}" title='Feature' aria-label="feature post toggle">
<svg id="option-feature-icon" class="icon">
<use id="option-feature-icon" xlink:href="/assets/images/global/sprite.svg#entypo-star" />
</svg>
</button><button id="option-published" class="option-inactive post-option-btn" data-active="{{$published}}" title='Published' aria-label="publish post toggle">
</button><button id="option-published" class="option-inactive post-option-btn" aria-pressed="{{$published}}" data-active="{{$published}}" title='Published' aria-label="publish post toggle">
<svg id="option-published-icon" class="icon">
<use id="option-published-icon" xlink:href="/assets/images/global/sprite.svg#entypo-globe" />
</svg>