Skip to content

Commit

Permalink
Migrate from Select.options to Select.selectedOptions (#6678)
Browse files Browse the repository at this point in the history
* Add selectedOptions as a performance improvement

Move from `options` to `selectedOptions` to reduce code and safe one array traversal.

See https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/selectedOptions for more information.

Will not work in IE11!

* Remove unnecessary .filter for selected options

Since we moved from `Select.options` to `Select.selectedOptions` we don't need to filter for selected options by ourselfs anymore.

Co-authored-by: Bill <bluebill1049@hotmail.com>
  • Loading branch information
krnlde and bluebill1049 committed Oct 1, 2021
1 parent 3a4c79b commit 59f0272
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion src/logic/getFieldValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function getFieldValue(_f: Field['_f']) {
}

if (isMultipleSelect(ref)) {
return getMultipleSelectValue(ref.options);
return getMultipleSelectValue(ref.selectedOptions);
}

if (isCheckBox(ref)) {
Expand Down
1 change: 0 additions & 1 deletion src/logic/getMultipleSelectValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export default (
options: HTMLOptionElement[] | HTMLOptionsCollection,
): string[] =>
[...options]
.filter(({ selected }): boolean => selected)
.map(({ value }): string => value);

0 comments on commit 59f0272

Please sign in to comment.