Skip to content

Commit

Permalink
Merge pull request #367 from mkocansey/v2.7
Browse files Browse the repository at this point in the history
highlight selected row when navigating with arrows
  • Loading branch information
mkocansey authored Oct 21, 2024
2 parents 9bc6e1d + fb8273d commit 009d8a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion public/css/bladewind-ui.min.css

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions public/js/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ class BladewindSelect {
enableKeyboardNavigation = () => {
dom_el(this.rootElement).addEventListener('keydown', (e) => {
if (e.key === "Enter") {
e.preventDefault();
unhide(this.itemsContainer);
dom_el(this.searchInput).focus()
if (!this.selectedItem) {
e.preventDefault();
unhide(this.itemsContainer);
dom_el(this.searchInput).focus();
} else {
hide(this.itemsContainer);
}
}
if (e.key === "Tab") {
if (e.key === "Tab" || e.key === "Escape") {
hide(this.itemsContainer);
}

Expand All @@ -78,6 +82,8 @@ class BladewindSelect {

this.selectedItem = e.key === 'ArrowDown' ? els[idx + 1] : els[idx - 1];
}
changeCssForDomArray(`${this.rootElement} .bw-select-item`, 'bg-slate-100/90', 'remove');
changeCss(this.selectedItem, 'bg-slate-100/90', 'add', true);
this.setValue(this.selectedItem);
this.callUserFunction(this.selectedItem);
}
Expand Down Expand Up @@ -129,7 +135,7 @@ class BladewindSelect {
let selected = (el.getAttribute('data-selected') !== null);
if (selected) this.setValue(el);
let isSelectable = (el.getAttribute('data-unselectable') === null);
if(isSelectable) {
if (isSelectable) {
el.addEventListener('click', () => {
this.setValue(el);
this.callUserFunction(el);
Expand All @@ -152,8 +158,8 @@ class BladewindSelect {
}

setValue = (item) => {
this.selectedValue = item.getAttribute('data-value');
let selectedLabel = item.getAttribute('data-label');
this.selectedValue = item ? item.getAttribute('data-value') : null;
let selectedLabel = item ? item.getAttribute('data-label') : null;
let svg = dom_el(`${this.rootElement} div[data-value="${this.selectedValue}"] svg`);
let input = dom_el(this.formInput);

Expand Down Expand Up @@ -200,7 +206,7 @@ class BladewindSelect {
}

unsetValue = (item) => {
this.selectedValue = item.getAttribute('data-value');
this.selectedValue = item ? item.getAttribute('data-value') : null;
// let selectedValue = item.getAttribute('data-value');
let svg = dom_el(`${this.rootElement} div[data-value="${this.selectedValue}"] svg`);
let input = dom_el(this.formInput);
Expand Down Expand Up @@ -316,7 +322,7 @@ class BladewindSelect {
}

callUserFunction = (item) => {
let user_function = item.getAttribute('data-user-function');
let user_function = item ? item.getAttribute('data-user-function') : null;
if (user_function !== null && user_function !== undefined) {
callUserFunction(
`${user_function}(
Expand Down

0 comments on commit 009d8a1

Please sign in to comment.