mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-08 08:52:19 +02:00
Accept page up/down to skip to the first/last options
This commit is contained in:
parent
cdd120f588
commit
b557de3400
|
@ -1278,6 +1278,8 @@ class Choices {
|
||||||
const escapeKey = 27;
|
const escapeKey = 27;
|
||||||
const upKey = 38;
|
const upKey = 38;
|
||||||
const downKey = 40;
|
const downKey = 40;
|
||||||
|
const pageUpKey = 33;
|
||||||
|
const pageDownKey = 34;
|
||||||
const ctrlDownKey = e.ctrlKey || e.metaKey;
|
const ctrlDownKey = e.ctrlKey || e.metaKey;
|
||||||
|
|
||||||
// If a user is typing and the dropdown is not active
|
// If a user is typing and the dropdown is not active
|
||||||
|
@ -1352,16 +1354,25 @@ class Choices {
|
||||||
this.showDropdown(true);
|
this.showDropdown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentEl = this.dropdown.querySelector(`.${this.config.classNames.highlightedState}`);
|
|
||||||
const directionInt = e.keyCode === downKey ? 1 : -1;
|
|
||||||
let nextEl;
|
|
||||||
|
|
||||||
this.canSearch = false;
|
this.canSearch = false;
|
||||||
|
|
||||||
if (currentEl) {
|
const directionInt = e.keyCode === downKey || e.keyCode === pageDownKey ? 1 : -1;
|
||||||
nextEl = getAdjacentEl(currentEl, '[data-choice-selectable]', directionInt);
|
const skipKey = e.metaKey || e.keyCode === pageDownKey || e.keyCode === pageUpKey;
|
||||||
|
|
||||||
|
let nextEl;
|
||||||
|
if (skipKey) {
|
||||||
|
if (directionInt > 0) {
|
||||||
|
nextEl = Array.from(this.dropdown.querySelectorAll('[data-choice-selectable]')).pop();
|
||||||
|
} else {
|
||||||
|
nextEl = this.dropdown.querySelector('[data-choice-selectable]');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
nextEl = this.dropdown.querySelector('[data-choice-selectable]');
|
const currentEl = this.dropdown.querySelector(`.${this.config.classNames.highlightedState}`);
|
||||||
|
if (currentEl) {
|
||||||
|
nextEl = getAdjacentEl(currentEl, '[data-choice-selectable]', directionInt);
|
||||||
|
} else {
|
||||||
|
nextEl = this.dropdown.querySelector('[data-choice-selectable]');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextEl) {
|
if (nextEl) {
|
||||||
|
@ -1393,7 +1404,9 @@ class Choices {
|
||||||
[enterKey]: onEnterKey,
|
[enterKey]: onEnterKey,
|
||||||
[escapeKey]: onEscapeKey,
|
[escapeKey]: onEscapeKey,
|
||||||
[upKey]: onDirectionKey,
|
[upKey]: onDirectionKey,
|
||||||
|
[pageUpKey]: onDirectionKey,
|
||||||
[downKey]: onDirectionKey,
|
[downKey]: onDirectionKey,
|
||||||
|
[pageDownKey]: onDirectionKey,
|
||||||
[deleteKey]: onDeleteKey,
|
[deleteKey]: onDeleteKey,
|
||||||
[backKey]: onDeleteKey,
|
[backKey]: onDeleteKey,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue