A11Y: deselect focused choice when using enter in multi-select (#12165)

This commit is contained in:
Joffrey JAFFEUX 2021-02-22 14:34:31 +01:00 committed by GitHub
parent f75e1867ff
commit d0d54bbead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

View File

@ -137,7 +137,17 @@ export default SelectKitComponent.extend({
}),
_onKeydown(event) {
if (event.keyCode === 8) {
if (
event.code === "Enter" &&
event.target.classList.contains("selected-name")
) {
event.stopPropagation();
this.selectKit.deselectByValue(event.target.dataset.value);
return false;
}
if (event.code === "Backspace") {
event.stopPropagation();
const input = this.getFilterInput();
@ -149,19 +159,14 @@ export default SelectKitComponent.extend({
if (selected.length) {
const lastSelected = selected[selected.length - 1];
if (lastSelected) {
if (lastSelected.classList.contains("is-highlighted")) {
if (lastSelected === document.activeElement) {
this.deselect(this.selectedContent.lastObject);
} else {
lastSelected.classList.add("is-highlighted");
lastSelected.focus();
}
}
}
}
} else {
const selected = this.element.querySelectorAll(
".select-kit-header .choice.select-kit-selected-name"
);
selected.forEach((s) => s.classList.remove("is-highlighted"));
}
return true;

View File

@ -115,6 +115,7 @@ export default Component.extend(
change: bind(this, this._onChangeWrapper),
select: bind(this, this.select),
deselect: bind(this, this.deselect),
deselectByValue: bind(this, this.deselectByValue),
append: bind(this, this.append),
onOpen: bind(this, this._onOpenWrapper),
@ -544,6 +545,15 @@ export default Component.extend(
this.selectKit.change(null, null);
},
deselectByValue(value) {
if (!value) {
return;
}
const item = this.itemForValue(value, this.selectedContent);
this.deselect(item);
},
append() {
// do nothing on general case
},

View File

@ -157,10 +157,6 @@
&:hover .d-icon:last-child {
color: var(--danger);
}
&.is-highlighted {
box-shadow: 0 0 2px var(--danger), 0 1px 0 rgba(0, 0, 0, 0.05);
}
}
}
}