Skip to content

Commit 88ceb83

Browse files
authored
fix(ui5-select): Selection now changes instantly (#2031)
1 parent 7951adc commit 88ceb83

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

packages/main/src/List.js

+15
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ class List extends UI5Element {
471471
return this.handleSingleSelect(item);
472472
}
473473

474+
handleSingleSelectAuto(item) {
475+
return this.handleSingleSelect(item);
476+
}
477+
474478
handleMultiSelect(item, selected) {
475479
item.selected = selected;
476480
return true;
@@ -595,6 +599,17 @@ class List extends UI5Element {
595599

596600
this._itemNavigation.update(target);
597601
this.fireEvent("item-focused", { item: target });
602+
603+
if (this.mode === ListMode.SingleSelectAuto) {
604+
this.onSelectionRequested({
605+
detail: {
606+
item: target,
607+
selectionComponentPressed: false,
608+
selected: true,
609+
key: event.detail.key,
610+
},
611+
});
612+
}
598613
}
599614

600615
onItemPress(event) {

packages/main/src/Select.js

+25-12
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,28 @@ class Select extends UI5Element {
360360
this.options[index].selected = true;
361361
}
362362

363-
_selectionChange(event) {
364-
const selectedItemIndex = this._getSelectedItemIndex(event.detail.item);
365-
363+
/**
364+
* The user clicked on an item from the list
365+
* @private
366+
*/
367+
_handleItemPress(event) {
368+
const item = event.detail.item;
369+
const selectedItemIndex = this._getSelectedItemIndex(item);
366370
this._select(selectedItemIndex);
371+
367372
this._toggleRespPopover();
368373
}
369374

375+
/**
376+
* The user used arrow up/down on the list
377+
* @private
378+
*/
379+
_handleSelectionChange(event) {
380+
const item = event.detail.selectedItems[0];
381+
const selectedItemIndex = this._getSelectedItemIndex(item);
382+
this._select(selectedItemIndex);
383+
}
384+
370385
_applyFocusAfterOpen() {
371386
if (!this._currentlySelectedOption) {
372387
return;
@@ -379,7 +394,13 @@ class Select extends UI5Element {
379394
}
380395

381396
_handlePickerKeydown(event) {
382-
this._handleArrowNavigation(event, false);
397+
if (isEscape(event) && this._isPickerOpen) {
398+
this._escapePressed = true;
399+
}
400+
401+
if (isEnter(event) || isSpace(event)) {
402+
this._shouldClosePopover = true;
403+
}
383404
}
384405

385406
_handleArrowNavigation(event, shouldFireEvent) {
@@ -403,14 +424,6 @@ class Select extends UI5Element {
403424
this._fireChangeEvent(this.options[nextIndex]);
404425
}
405426
}
406-
407-
if (isEscape(event) && this._isPickerOpen) {
408-
this._escapePressed = true;
409-
}
410-
411-
if (isEnter(event) || isSpace(event)) {
412-
this._shouldClosePopover = true;
413-
}
414427
}
415428

416429
_getNextOptionIndex() {

packages/main/src/SelectPopover.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
</div>
2424
</div>
2525

26-
<ui5-list mode="SingleSelect" separators="None" @keydown="{{_handlePickerKeydown}}" @ui5-item-press="{{_selectionChange}}">
26+
<ui5-list mode="SingleSelectAuto" separators="None" @keydown="{{_handlePickerKeydown}}" @ui5-selection-change="{{_handleSelectionChange}}" @ui5-item-press="{{_handleItemPress}}">
2727
{{#each _syncedOptions}}
2828
<ui5-li ?selected="{{this.selected}}" icon="{{this.icon}}" id="{{this.id}}-li">
2929
{{this.textContent}}
3030
</ui5-li>
3131
{{/each}}
3232
</ui5-list>
3333
</ui5-responsive-popover>
34-
{{/if}}
34+
{{/if}}

packages/main/src/types/ListMode.js

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ const ListModes = {
3434
*/
3535
SingleSelectEnd: "SingleSelectEnd",
3636

37+
/**
38+
* Selected item is highlighted and selection is changed upon arrow navigation
39+
* (only one list item can be selected - this is always the focused item).
40+
* @public
41+
* @type {SingleSelectAuto}
42+
*/
43+
SingleSelectAuto: "SingleSelectAuto",
44+
3745
/**
3846
* Multi selection mode (more than one list item can be selected).
3947
* @public

0 commit comments

Comments
 (0)