From 32c03364b85acec54e89e078a9013e04c5eec857 Mon Sep 17 00:00:00 2001 From: stephanrotolante Date: Sat, 19 Oct 2019 13:05:09 -0400 Subject: [PATCH] refactor(Dropdown): fixed the first option preselected --- src/modules/Dropdown/Dropdown.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/modules/Dropdown/Dropdown.js b/src/modules/Dropdown/Dropdown.js index 5b460bb4eb..c34bca1a05 100644 --- a/src/modules/Dropdown/Dropdown.js +++ b/src/modules/Dropdown/Dropdown.js @@ -938,15 +938,17 @@ export default class Dropdown extends Component { let newSelectedIndex - // update the selected index - if (!selectedIndex || selectedIndex < 0) { - const firstIndex = enabledIndicies[0] + if (selectedIndex === undefined) { + newSelectedIndex = -1 + } else if (!selectedIndex || selectedIndex < 0) { + // update the selected index + // const firstIndex = enabledIndicies[0] // Select the currently active item, if none, use the first item. // Multiple selects remove active items from the list, // their initial selected index should be 0. newSelectedIndex = multiple - ? firstIndex + ? -1 : this.getMenuItemIndexByValue(value, options) || enabledIndicies[0] } else if (multiple) { // multiple selects remove options from the menu as they are made active @@ -962,10 +964,6 @@ export default class Dropdown extends Component { newSelectedIndex = _.includes(enabledIndicies, activeIndex) ? activeIndex : undefined } - if (!newSelectedIndex || newSelectedIndex < 0) { - newSelectedIndex = enabledIndicies[0] - } - this.setState({ selectedIndex: newSelectedIndex }) }