Exclude disabled options from search
This commit is contained in:
parent
aad018dad0
commit
7d6f2591f4
2 changed files with 5 additions and 2 deletions
|
@ -6,7 +6,7 @@
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "3.0.0",
|
"version": "3.0.1",
|
||||||
"url": "https://darkwiiplayer.github.io/BetterSelect/",
|
"url": "https://darkwiiplayer.github.io/BetterSelect/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"definitions": "tsc src/*.js --declaration --allowJs --emitDeclarationOnly"
|
"definitions": "tsc src/*.js --declaration --allowJs --emitDeclarationOnly"
|
||||||
|
|
|
@ -445,18 +445,21 @@ export class BetterSelect extends HTMLElement {
|
||||||
this.close()
|
this.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const candidates = /** @type {HTMLElement[]} */(Array.from(this.list.children).filter(child => !child.hasAttribute("hidden")))
|
const candidates = /** @type {HTMLElement[]} */(Array.from(this.list.children).filter(child => !child.hasAttribute("hidden") && !child.part.contains("disabled")))
|
||||||
if (candidates.length) {
|
if (candidates.length) {
|
||||||
this.setOption(candidates[0])
|
this.setOption(candidates[0])
|
||||||
this.close()
|
this.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static searchHideDisabled = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} value
|
* @param {string} value
|
||||||
* @param {HTMLElement} item
|
* @param {HTMLElement} item
|
||||||
*/
|
*/
|
||||||
match(value, item) {
|
match(value, item) {
|
||||||
|
if (/** @type {Object} */(value && this.constructor).searchHideDisabled && item.part.contains("disabled")) return false
|
||||||
return item.innerText.toLowerCase().match(value.toLowerCase())
|
return item.innerText.toLowerCase().match(value.toLowerCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue