Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Dropdown): fixed the first option preselected #3814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/modules/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
}

Expand Down