Skip to content

Commit df8a6f2

Browse files
ayaan-qadrigasman
authored andcommitted
Added aria-expanded attribute to add new column button (wagtail#12680)
1 parent 2e08d84 commit df8a6f2

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Changelog
4040
* Fix: Ensure new `ListBlock` instances get created with unique IDs in the admin client for accessibility and mini-map element references (Srishti Jaiswal)
4141
* Fix: Return never-cache HTTP headers when serving pages and documents with view restrictions (Krystian Magdziarz, Dawid Bugajewski)
4242
* Fix: Implement `get_block_by_content_path` on `ImageBlock` to prevent errors on commenting (Matt Westcott)
43+
* Fix: Add `aria-expanded` attribute to new column button on `TypedTableBlock` to reflect menu state (Ayaan Qadri, Scott Cranfill)
4344
* Docs: Move the model reference page from reference/pages to the references section as it covers all Wagtail core models (Srishti Jaiswal)
4445
* Docs: Move the panels reference page from references/pages to the references section as panels are available for any model editing, merge panels API into this page (Srishti Jaiswal)
4546
* Docs: Move the tags documentation to standalone advanced topic, instead of being inside the reference/pages section (Srishti Jaiswal)

client/src/entrypoints/contrib/typed_table_block/__snapshots__/typed_table_block.test.js.snap

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ exports[`wagtail.contrib.typed_table_block.blocks.TypedTableBlock it renders cor
2424
<div class="typed-table-block__wrapper">
2525
<table>
2626
<thead>
27-
<tr><th aria-hidden="true"></th><th><input type="hidden" name="mytable-column-0-type" value="test_block_a"><input type="hidden" name="mytable-column-0-order" value="0"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" title="Insert column">
27+
<tr><th aria-hidden="true"></th><th><input type="hidden" name="mytable-column-0-type" value="test_block_a"><input type="hidden" name="mytable-column-0-order" value="0"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" aria-expanded="false" title="Insert column">
2828
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
2929
</button><input type="text" name="mytable-column-0-heading" class="column-heading" placeholder="Column heading"><button type="button" class="button button-secondary button-small button--icon text-replace no delete-column" aria-label="Delete column" title="Delete column">
3030
<svg class="icon icon-bin icon" aria-hidden="true"><use href="#icon-bin"></use></svg>
31-
</button></th><th><input type="hidden" name="mytable-column-1-type" value="test_block_b"><input type="hidden" name="mytable-column-1-order" value="1"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" title="Insert column">
31+
</button></th><th><input type="hidden" name="mytable-column-1-type" value="test_block_b"><input type="hidden" name="mytable-column-1-order" value="1"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" aria-expanded="false" title="Insert column">
3232
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
3333
</button><input type="text" name="mytable-column-1-heading" class="column-heading" placeholder="Column heading"><button type="button" class="button button-secondary button-small button--icon text-replace no delete-column" aria-label="Delete column" title="Delete column">
3434
<svg class="icon icon-bin icon" aria-hidden="true"><use href="#icon-bin"></use></svg>
3535
</button></th><th class="control-cell">
36-
<button type="button" class="button button-small button-secondary append-column button--icon text-replace white" data-append-column="" aria-label="Add column" title="Add column"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></button>
36+
<button type="button" class="button button-small button-secondary append-column button--icon text-replace white" aria-expanded="false" data-append-column="" aria-label="Add column" title="Add column"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></button>
3737
</th></tr>
3838
</thead>
3939
<tbody><tr><td class="control-cell"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-row" aria-label="Insert row" title="Insert row">
@@ -130,16 +130,16 @@ exports[`wagtail.contrib.typed_table_block.blocks.TypedTableBlock setError passe
130130
<div class="typed-table-block__wrapper">
131131
<table>
132132
<thead>
133-
<tr><th aria-hidden="true"></th><th><input type="hidden" name="mytable-column-0-type" value="test_block_a"><input type="hidden" name="mytable-column-0-order" value="0"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" title="Insert column">
133+
<tr><th aria-hidden="true"></th><th><input type="hidden" name="mytable-column-0-type" value="test_block_a"><input type="hidden" name="mytable-column-0-order" value="0"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" aria-expanded="false" title="Insert column">
134134
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
135135
</button><input type="text" name="mytable-column-0-heading" class="column-heading" placeholder="Column heading"><button type="button" class="button button-secondary button-small button--icon text-replace no delete-column" aria-label="Delete column" title="Delete column">
136136
<svg class="icon icon-bin icon" aria-hidden="true"><use href="#icon-bin"></use></svg>
137-
</button></th><th><input type="hidden" name="mytable-column-1-type" value="test_block_b"><input type="hidden" name="mytable-column-1-order" value="1"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" title="Insert column">
137+
</button></th><th><input type="hidden" name="mytable-column-1-type" value="test_block_b"><input type="hidden" name="mytable-column-1-order" value="1"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" aria-expanded="false" title="Insert column">
138138
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
139139
</button><input type="text" name="mytable-column-1-heading" class="column-heading" placeholder="Column heading"><button type="button" class="button button-secondary button-small button--icon text-replace no delete-column" aria-label="Delete column" title="Delete column">
140140
<svg class="icon icon-bin icon" aria-hidden="true"><use href="#icon-bin"></use></svg>
141141
</button></th><th class="control-cell">
142-
<button type="button" class="button button-small button-secondary append-column button--icon text-replace white" data-append-column="" aria-label="Add column" title="Add column"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></button>
142+
<button type="button" class="button button-small button-secondary append-column button--icon text-replace white" aria-expanded="false" data-append-column="" aria-label="Add column" title="Add column"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></button>
143143
</th></tr>
144144
</thead>
145145
<tbody><tr><td class="control-cell"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-row" aria-label="Insert row" title="Insert row">
@@ -236,16 +236,16 @@ exports[`wagtail.contrib.typed_table_block.blocks.TypedTableBlock setError shows
236236
<div class="typed-table-block__wrapper">
237237
<table>
238238
<thead>
239-
<tr><th aria-hidden="true"></th><th><input type="hidden" name="mytable-column-0-type" value="test_block_a"><input type="hidden" name="mytable-column-0-order" value="0"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" title="Insert column">
239+
<tr><th aria-hidden="true"></th><th><input type="hidden" name="mytable-column-0-type" value="test_block_a"><input type="hidden" name="mytable-column-0-order" value="0"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" aria-expanded="false" title="Insert column">
240240
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
241241
</button><input type="text" name="mytable-column-0-heading" class="column-heading" placeholder="Column heading"><button type="button" class="button button-secondary button-small button--icon text-replace no delete-column" aria-label="Delete column" title="Delete column">
242242
<svg class="icon icon-bin icon" aria-hidden="true"><use href="#icon-bin"></use></svg>
243-
</button></th><th><input type="hidden" name="mytable-column-1-type" value="test_block_b"><input type="hidden" name="mytable-column-1-order" value="1"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" title="Insert column">
243+
</button></th><th><input type="hidden" name="mytable-column-1-type" value="test_block_b"><input type="hidden" name="mytable-column-1-order" value="1"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-column" aria-label="Insert column" aria-expanded="false" title="Insert column">
244244
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
245245
</button><input type="text" name="mytable-column-1-heading" class="column-heading" placeholder="Column heading"><button type="button" class="button button-secondary button-small button--icon text-replace no delete-column" aria-label="Delete column" title="Delete column">
246246
<svg class="icon icon-bin icon" aria-hidden="true"><use href="#icon-bin"></use></svg>
247247
</button></th><th class="control-cell">
248-
<button type="button" class="button button-small button-secondary append-column button--icon text-replace white" data-append-column="" aria-label="Add column" title="Add column"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></button>
248+
<button type="button" class="button button-small button-secondary append-column button--icon text-replace white" aria-expanded="false" data-append-column="" aria-label="Add column" title="Add column"><svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg></button>
249249
</th></tr>
250250
</thead>
251251
<tbody><tr><td class="control-cell"><button type="button" class="button button-secondary button-small button--icon text-replace prepend-row" aria-label="Insert row" title="Insert row">

client/src/entrypoints/contrib/typed_table_block/typed_table_block.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class TypedTableBlock {
7878
<tr>
7979
<th aria-hidden="true"></th>
8080
<th class="control-cell">
81-
<button type="button" class="button button-small button-secondary append-column" data-append-column>
81+
<button type="button" class="button button-small button-secondary append-column" aria-expanded="false" data-append-column>
8282
${h(strings.ADD_COLUMN)}
8383
</button>
8484
</th>
@@ -148,12 +148,12 @@ export class TypedTableBlock {
148148
).text(childBlockDef.meta.label);
149149
columnTypeButton.on('click', () => {
150150
if (this.addColumnCallback) this.addColumnCallback(childBlockDef);
151-
this.hideAddColumnMenu();
151+
this.hideAddColumnMenu(this.addColumnMenuTrigger);
152152
});
153153
const li = $('<li></li>').append(columnTypeButton);
154154
this.addColumnMenu.append(li);
155155
});
156-
this.addColumnMenuBaseElement = null; // the element the add-column menu is attached to
156+
this.addColumnMenuTrigger = null; // the element the add-column menu is attached to
157157

158158
this.appendColumnButton.on('click', () => {
159159
this.toggleAddColumnMenu(this.appendColumnButton, (chosenBlockDef) => {
@@ -173,23 +173,26 @@ export class TypedTableBlock {
173173
}
174174
}
175175

176-
showAddColumnMenu(baseElement, callback) {
177-
this.addColumnMenuBaseElement = baseElement;
178-
baseElement.after(this.addColumnMenu);
176+
showAddColumnMenu(triggeredElement, callback) {
177+
this.addColumnMenuTrigger?.attr('aria-expanded', 'false');
178+
this.addColumnMenuTrigger = triggeredElement;
179+
triggeredElement.after(this.addColumnMenu);
180+
triggeredElement.attr('aria-expanded', 'true');
179181
this.addColumnMenu.show();
180182
this.addColumnCallback = callback;
181183
}
182184

183-
hideAddColumnMenu() {
185+
hideAddColumnMenu(triggeredElement) {
186+
triggeredElement.attr('aria-expanded', 'false');
184187
this.addColumnMenu.hide();
185-
this.addColumnMenuBaseElement = null;
188+
this.addColumnMenuTrigger = null;
186189
}
187190

188-
toggleAddColumnMenu(baseElement, callback) {
189-
if (this.addColumnMenuBaseElement === baseElement) {
190-
this.hideAddColumnMenu();
191+
toggleAddColumnMenu(triggeredElement, callback) {
192+
if (this.addColumnMenuTrigger === triggeredElement) {
193+
this.hideAddColumnMenu(triggeredElement);
191194
} else {
192-
this.showAddColumnMenu(baseElement, callback);
195+
this.showAddColumnMenu(triggeredElement, callback);
193196
}
194197
}
195198

@@ -271,10 +274,13 @@ export class TypedTableBlock {
271274
const prependColumnButton = $(`<button type="button"
272275
class="button button-secondary button-small button--icon text-replace prepend-column"
273276
aria-label="${h(this.blockDef.meta.strings.INSERT_COLUMN)}"
277+
aria-expanded="false"
274278
title="${h(this.blockDef.meta.strings.INSERT_COLUMN)}">
275279
<svg class="icon icon-plus icon" aria-hidden="true"><use href="#icon-plus"></use></svg>
276280
</button>`);
281+
277282
$(newHeaderCell).append(prependColumnButton);
283+
278284
prependColumnButton.on('click', () => {
279285
this.toggleAddColumnMenu(prependColumnButton, (chosenBlockDef) => {
280286
this.insertColumn(column.position, chosenBlockDef, {
@@ -331,6 +337,7 @@ export class TypedTableBlock {
331337
.attr('aria-label', this.blockDef.meta.strings.ADD_COLUMN)
332338
.addClass('button--icon text-replace white')
333339
.attr('aria-label', this.blockDef.meta.strings.ADD_COLUMN)
340+
.attr('aria-expanded', 'false')
334341
.attr('title', this.blockDef.meta.strings.ADD_COLUMN);
335342

336343
if (opts && opts.addInitialRow && this.tbody.children.length === 0) {

docs/releases/6.4.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ depth: 1
5252
* Ensure new `ListBlock` instances get created with unique IDs in the admin client for accessibility and mini-map element references (Srishti Jaiswal)
5353
* Return never-cache HTTP headers when serving pages and documents with view restrictions (Krystian Magdziarz, Dawid Bugajewski)
5454
* Implement `get_block_by_content_path` on `ImageBlock` to prevent errors on commenting (Matt Westcott)
55+
* Add `aria-expanded` attribute to new column button on `TypedTableBlock` to reflect menu state (Ayaan Qadri, Scott Cranfill)
5556

5657
### Documentation
5758

0 commit comments

Comments
 (0)