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

fix(ui5-combobox): Autocomplete on Safari #3999

Merged
merged 5 commits into from
Oct 19, 2021
Merged
Changes from 1 commit
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
43 changes: 25 additions & 18 deletions packages/main/src/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ class ComboBox extends UI5Element {
}

this._initialRendering = false;
this._isKeyNavigation = false;
}

async onAfterRendering() {
Expand All @@ -415,6 +414,13 @@ class ComboBox extends UI5Element {
this._itemFocused = false;
this.toggleValueStatePopover(this.shouldOpenValueStateMessagePopover);
this.storeResponsivePopoverWidth();

if (this._autocomplete && this.filterValue !== this.value) {
this.inner.setSelectionRange(
this._isKeyNavigation ? "" : this.filterValue.length,
this.value.length
d3xter666 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}

shouldClosePopover() {
Expand All @@ -426,6 +432,8 @@ class ComboBox extends UI5Element {

this._lastValue = this.value;

this._autocomplete = false;

!isPhone() && event.target.setSelectionRange(0, this.value.length);
}

Expand Down Expand Up @@ -529,10 +537,11 @@ class ComboBox extends UI5Element {
this._clearFocus();

// autocomplete
if (this._autocomplete && value !== "") {
const item = this._autoCompleteValue(value);
if (this._autocomplete) {
const item = this._getFirstMatchingItem(value);
this._applyAtomicValueAndSelection(item, value, true);

if (!this._selectionChanged && (item && !item.selected && !item.isGroupItem)) {
if (value !== "" && !this._selectionChanged && (item && !item.selected && !item.isGroupItem)) {
this.fireEvent("selection-change", {
item,
});
Expand All @@ -549,7 +558,7 @@ class ComboBox extends UI5Element {
return;
}

if (!this._filteredItems.length) {
if (!this._filteredItems.length || value === "") {
this._closeRespPopover();
} else {
this._openRespPopover();
Expand Down Expand Up @@ -609,7 +618,8 @@ class ComboBox extends UI5Element {
this._filteredItems[indexOfItem].selected = true;

// autocomplete
const item = this._autoCompleteValue(this.value);
const item = this._getFirstMatchingItem(this.value);
this._applyAtomicValueAndSelection(item, "", true);

if ((item && !item.selected)) {
this.fireEvent("selection-change", {
Expand All @@ -624,6 +634,7 @@ class ComboBox extends UI5Element {
_keydown(event) {
const isArrowKey = isDown(event) || isUp(event);
this._autocomplete = !(isBackSpace(event) || isDelete(event));
this._isKeyNavigation = false;

if (isArrowKey) {
this.handleArrowKeyPress(event);
Expand Down Expand Up @@ -690,7 +701,7 @@ class ComboBox extends UI5Element {
}
}

_autoCompleteValue(current) {
_getFirstMatchingItem(current) {
const currentlyFocusedItem = this.items.find(item => item.focused === true);

if (currentlyFocusedItem && currentlyFocusedItem.isGroupItem) {
Expand All @@ -700,24 +711,20 @@ class ComboBox extends UI5Element {

const matchingItems = this._startsWithMatchingItems(current).filter(item => !item.isGroupItem);

let value;
if (matchingItems.length) {
value = matchingItems[0] ? matchingItems[0].text : current;
} else {
value = current;
}

this._applyAtomicValueAndSelection(value, this._isKeyNavigation || matchingItems.length);

if (matchingItems.length) {
return matchingItems[0];
}
}

_applyAtomicValueAndSelection(value, highlightValue) {
_applyAtomicValueAndSelection(item, filterValue, highlightValue) {
if (!item) {
return;
}

const value = (item && item.text) || "";
this.inner.value = value;
if (highlightValue) {
this.inner.setSelectionRange(this.filterValue.length, value.length);
this.inner.setSelectionRange(filterValue.length, value.length);
}
this.value = value;
}
Expand Down