Skip to content

Commit

Permalink
Selected options in Content Selector get deselected on dropdown scroll
Browse files Browse the repository at this point in the history
…#3305

- BaseRichComboBox: comboBox.addOption doesn't select item that is supposed to be selected
- DropdownList: navigating to the first selected row only if dropdown was not open yet
- no need to fetch a next batch if dropdown is already closed
  • Loading branch information
ashklianko authored and alansemenov committed Oct 19, 2023
1 parent fd8c00b commit d6ded85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,21 @@ export class DropdownList<OPTION_DISPLAY_VALUE> {
}

showDropdown(selectedOptions?: Option<OPTION_DISPLAY_VALUE>[], noOptionsText?: string) {
const isShown: boolean = this.isDropdownShown();

if (this.hasOptions()) {
this.emptyDropdown.hide();
this.dropdownGrid.show();
this.dropdownGrid.adjustGridHeight();

if (selectedOptions) {
this.dropdownGrid.markSelections(selectedOptions);
if (selectedOptions.length > 0) {
this.dropdownGrid.markReadOnly(selectedOptions);
this.navigateToRowIfNotActive(selectedOptions[0]);

if (!isShown) {
this.navigateToRowIfNotActive(selectedOptions[0]);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export class BaseRichComboBox<OPTION_DATA_TYPE, LOADER_DATA_TYPE>
}

private loadNextRangeIfNeeded(containerEl: HTMLElement, handler: () => void): void {
if (this.isScrolledToBottom(containerEl)) {
if (this.isScrolledToBottom(containerEl) && this.comboBox.isDropdownShown()) {
handler();
}
}
Expand All @@ -378,9 +378,10 @@ export class BaseRichComboBox<OPTION_DATA_TYPE, LOADER_DATA_TYPE>

private handleRangeLoad(handler: () => void) {
const viewportEl: HTMLElement = this.comboBox.getComboBoxDropdownGrid().getGrid().getViewportEl();
const loadHandler = () => this.loadNextRangeIfNeeded(viewportEl, handler);

viewportEl.addEventListener('scroll', () => this.loadNextRangeIfNeeded(viewportEl, handler));
this.onLoaded(() => this.loadNextRangeIfNeeded(viewportEl, handler));
viewportEl.addEventListener('scroll', loadHandler);
this.onLoaded(loadHandler);
}

private setupLoader(loader: BaseLoader<LOADER_DATA_TYPE>) {
Expand Down Expand Up @@ -418,26 +419,12 @@ export class BaseRichComboBox<OPTION_DATA_TYPE, LOADER_DATA_TYPE>
}
}

private handleLoadedData(event: LoadedDataEvent<LOADER_DATA_TYPE>) {
private handleLoadedData(event: LoadedDataEvent<LOADER_DATA_TYPE>): Q.Promise<void> {
this.errorContainer.hide();
const optionCount: number = this.getOptionCount();

return this.createOptions(event.getData().map(this.loadedItemToDisplayValue.bind(this))).then(
(options: Option<OPTION_DATA_TYPE>[]) => {
let appendOptions: boolean = false;

if (event.isPostLoad() && optionCount > 0) {
const lastOption: Option<OPTION_DATA_TYPE> = this.getOptionByRow(optionCount - 1);
appendOptions = options.length > optionCount && options[optionCount - 1].getValue() === lastOption.getValue();
}

if (appendOptions) {
for (let i: number = optionCount; i < options.length; i++) {
this.comboBox.addOption(options[i]);
}
} else {
this.comboBox.setOptions(options, event.isPostLoad());
}

this.comboBox.setOptions(options, event.isPostLoad());
this.notifyLoaded(options.map((option) => option.getDisplayValue()), event.isPostLoad());
return;
});
Expand Down

0 comments on commit d6ded85

Please sign in to comment.