Skip to content

Commit

Permalink
Add aria labels to toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
clairefields15 authored and luin committed Aug 25, 2023
1 parent 3ed59c3 commit 8ecff87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions modules/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,15 @@ class Toolbar extends Module<ToolbarProps> {
}
Toolbar.DEFAULTS = {};

function addButton(container: HTMLElement, format: string, value?: unknown) {
function addButton(container: HTMLElement, format: string, value?: string) {
const input = document.createElement('button');
input.setAttribute('type', 'button');
input.setAttribute('aria-label', format);
input.classList.add(`ql-${format}`);
input.setAttribute('aria-pressed', 'false');
if (value != null) {
// @ts-expect-error
input.value = value;
input.setAttribute('aria-label', `${value} ${format}`);
}
container.appendChild(input);
}
Expand All @@ -215,6 +216,7 @@ function addControls(
groups = [groups];
}
groups.forEach((controls: any) => {
console.log({ controls });
const group = document.createElement('span');
group.classList.add('ql-formats');
controls.forEach((control: any) => {
Expand Down
1 change: 1 addition & 0 deletions themes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class BaseTheme extends Theme {
) {
this.pickers = Array.from(selects).map((select) => {
if (select.classList.contains('ql-align')) {
select.setAttribute('aria-label', 'Align text');
if (select.querySelector('option') == null) {
fillSelect(select, ALIGNS);
}
Expand Down
7 changes: 4 additions & 3 deletions ui/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ class Picker {
item.tabIndex = '0';
item.setAttribute('role', 'button');
item.classList.add('ql-picker-item');
if (option.hasAttribute('value')) {
// @ts-expect-error Fix me later
item.setAttribute('data-value', option.getAttribute('value'));
const value = option.getAttribute('value');
if (value) {
item.setAttribute('data-value', value);
}
if (option.textContent) {
item.setAttribute('data-label', option.textContent);
item.setAttribute('aria-label', option.textContent);
}
item.addEventListener('click', () => {
this.selectItem(item, true);
Expand Down

0 comments on commit 8ecff87

Please sign in to comment.