Skip to content

Commit

Permalink
fix: exclude hidden input from dropdown select options (#2224)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-ico authored Nov 30, 2023
1 parent c9fde04 commit d5e2e5b
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ const readDisabled = (element: Element) => {
};

const readOptions = (hostElement: HTMLElement): SelectOption[] => {
return Array.from(hostElement.children).map((x) => ({
const children = Array.from(hostElement.children);
const options = children.filter(
(x: HTMLElement) => x.tagName !== 'INPUT' && x.hidden === false
);
return options.map((x) => ({
label: x.textContent.trim(),
value: x.getAttribute('value') ?? readValue(x),
disabled: readDisabled(x),
Expand Down Expand Up @@ -458,11 +462,9 @@ export class DropdownSelect {

handleClick = () => {
this.setOpen(!this.open);

const indexOfValue = readOptions(this.hostElement).findIndex(
({ value }) => value === this.value
);

if (indexOfValue > -1) {
setTimeout(() => {
this.bringIntoView(indexOfValue);
Expand Down

0 comments on commit d5e2e5b

Please sign in to comment.