Skip to content
Draft
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
34 changes: 34 additions & 0 deletions packages/main/src/DynamicDateRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ class DynamicDateRange extends UI5Element {
@property({ type: Object })
_currentOption?: IDynamicDateRangeOption;

_lastSelectedOption?: IDynamicDateRangeOption;

_shouldFocusLastSelected = false;

@property({ type: Object })
currentValue?: DynamicDateRangeValue;

Expand All @@ -198,6 +202,15 @@ class DynamicDateRange extends UI5Element {
this._focusSelectedItem();
}

onAfterRendering() {
if (this._shouldFocusLastSelected) {
setTimeout(() => {
this._focusLastSelectedItem();
}, 0);
this._shouldFocusLastSelected = false;
}
}

/**
* Creates and normalizes options from the options string
*/
Expand Down Expand Up @@ -241,6 +254,25 @@ class DynamicDateRange extends UI5Element {
}
}

_focusLastSelectedItem() {
if (!this._lastSelectedOption) {
return;
}

// Ensure the list exists and has items
if (!this._list || !this._list.items.length) {
return;
}

// Find the index of the last selected option in the options array
const optionIndex = this.optionsObjects.findIndex(option => option.operator === this._lastSelectedOption?.operator);

if (optionIndex >= 0 && optionIndex < this._list.items.length) {
const listItem = this._list.items[optionIndex];
this._list.focusItem(listItem as ListItem);
}
}

/**
* Defines whether the value help icon is hidden
* @private
Expand All @@ -263,6 +295,7 @@ class DynamicDateRange extends UI5Element {

_selectOption(e: CustomEvent): void {
this._currentOption = this.optionsObjects.find(option => option.text === e.detail.item.textContent);
this._lastSelectedOption = this._currentOption;

if (!this._currentOption?.template) {
this.currentValue = this._currentOption?.parse(this._currentOption.text);
Expand Down Expand Up @@ -325,6 +358,7 @@ class DynamicDateRange extends UI5Element {

onButtonBackClick() {
this._currentOption = undefined;
this._shouldFocusLastSelected = true;
}

/**
Expand Down
Loading