mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 20:08:26 +00:00
A11Y: deselect focused choice when using enter in multi-select (#12165)
This commit is contained in:
parent
f75e1867ff
commit
d0d54bbead
@ -137,7 +137,17 @@ export default SelectKitComponent.extend({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
_onKeydown(event) {
|
_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();
|
event.stopPropagation();
|
||||||
|
|
||||||
const input = this.getFilterInput();
|
const input = this.getFilterInput();
|
||||||
@ -149,19 +159,14 @@ export default SelectKitComponent.extend({
|
|||||||
if (selected.length) {
|
if (selected.length) {
|
||||||
const lastSelected = selected[selected.length - 1];
|
const lastSelected = selected[selected.length - 1];
|
||||||
if (lastSelected) {
|
if (lastSelected) {
|
||||||
if (lastSelected.classList.contains("is-highlighted")) {
|
if (lastSelected === document.activeElement) {
|
||||||
this.deselect(this.selectedContent.lastObject);
|
this.deselect(this.selectedContent.lastObject);
|
||||||
} else {
|
} 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;
|
return true;
|
||||||
|
@ -115,6 +115,7 @@ export default Component.extend(
|
|||||||
change: bind(this, this._onChangeWrapper),
|
change: bind(this, this._onChangeWrapper),
|
||||||
select: bind(this, this.select),
|
select: bind(this, this.select),
|
||||||
deselect: bind(this, this.deselect),
|
deselect: bind(this, this.deselect),
|
||||||
|
deselectByValue: bind(this, this.deselectByValue),
|
||||||
append: bind(this, this.append),
|
append: bind(this, this.append),
|
||||||
|
|
||||||
onOpen: bind(this, this._onOpenWrapper),
|
onOpen: bind(this, this._onOpenWrapper),
|
||||||
@ -544,6 +545,15 @@ export default Component.extend(
|
|||||||
this.selectKit.change(null, null);
|
this.selectKit.change(null, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
deselectByValue(value) {
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = this.itemForValue(value, this.selectedContent);
|
||||||
|
this.deselect(item);
|
||||||
|
},
|
||||||
|
|
||||||
append() {
|
append() {
|
||||||
// do nothing on general case
|
// do nothing on general case
|
||||||
},
|
},
|
||||||
|
@ -157,10 +157,6 @@
|
|||||||
&:hover .d-icon:last-child {
|
&:hover .d-icon:last-child {
|
||||||
color: var(--danger);
|
color: var(--danger);
|
||||||
}
|
}
|
||||||
|
|
||||||
&.is-highlighted {
|
|
||||||
box-shadow: 0 0 2px var(--danger), 0 1px 0 rgba(0, 0, 0, 0.05);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user