Semantic-UI-React icon indicating copy to clipboard operation
Semantic-UI-React copied to clipboard

Dropdown: Incorrect behavior when loading options dynamic.

Open sergeushenecz opened this issue 3 years ago • 3 comments

Bug Report

Dropdown: Incorrect behavior when loading options dynamic.

Steps

I added custom options to the end and name it 'Load more'. When I click on the load more option I dynamically load options from backend and merge with the previous options. But position reset and move to the top. The behavior reproduces when the selected element in the dropdown exists and is disabled.

I found a place where the resetting position. If I have selected an item and it disabled after click 'load more' It goes to https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/Dropdown.js#L90 https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/utils/getSelectedIndex.js#L33 we exclude the disabled item and therefore selectedIndex will be set to 0.

And in the https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/Dropdown.js#L175 prevState.selectedIndex !== this.state.selectedIndex will be true and resetting postion

I removed this check and it started working as expected https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/utils/getSelectedIndex.js#L33
Can you explain what's the check for? and maybe we can fix it?

Expected Result

The position in the view after added dynamic options not reset.

Actual Result

The position in the view after added dynamic options reset.

Version

2.0.1

Testcase

sergeushenecz avatar Nov 18 '20 16:11 sergeushenecz

Please create a simple CodeSandbox with a repro case...

layershifter avatar Nov 18 '20 18:11 layershifter

@layershifter https://codesandbox.io/s/semantic-ui-example-forked-i33hg?file=/example.js

sergeushenecz avatar Nov 18 '20 19:11 sergeushenecz

@layershifter Could you please checking link above and to confirm this is a bug or not?

sergeushenecz avatar Jan 30 '21 14:01 sergeushenecz