-
Notifications
You must be signed in to change notification settings - Fork 77
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(combobox, input-time-zone): fix initial item selection delay #11326
Changes from all commits
b6b5830
c7db265
ffc7ee8
f109f8d
ce7054c
6446fb6
ae49554
d43f04d
77db412
94f580d
7f18667
9b1a4d6
f1c146d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,10 +107,6 @@ export class Combobox | |
|
||
// #region Private Properties | ||
|
||
private internalComboboxChangeEvent = (): void => { | ||
this.calciteComboboxChange.emit(); | ||
}; | ||
|
||
private allSelectedIndicatorChipEl: Chip["el"]; | ||
|
||
private chipContainerEl: HTMLDivElement; | ||
|
@@ -119,7 +115,9 @@ export class Combobox | |
|
||
defaultValue: Combobox["value"]; | ||
|
||
private emitComboboxChange = debounce(this.internalComboboxChangeEvent, 0); | ||
private emitComboboxChange(): void { | ||
this.calciteComboboxChange.emit(); | ||
} | ||
|
||
private get effectiveFilterProps(): string[] { | ||
if (!this.filterProps) { | ||
|
@@ -216,6 +214,8 @@ export class Combobox | |
|
||
private groupData: GroupData[]; | ||
|
||
private groupItems: HTMLCalciteComboboxItemGroupElement["el"][] = []; | ||
|
||
private guid = guid(); | ||
|
||
private ignoreSelectedEventsFlag = false; | ||
|
@@ -224,6 +224,8 @@ export class Combobox | |
|
||
private internalValueChangeFlag = false; | ||
|
||
private items: HTMLCalciteComboboxItemElement["el"][] = []; | ||
|
||
labelEl: Label["el"]; | ||
|
||
private listContainerEl: HTMLDivElement; | ||
|
@@ -278,12 +280,6 @@ export class Combobox | |
|
||
@state() compactSelectionDisplay = false; | ||
|
||
@state() groupItems: HTMLCalciteComboboxItemGroupElement["el"][] = []; | ||
|
||
@state() items: HTMLCalciteComboboxItemElement["el"][] = []; | ||
|
||
@state() needsIcon: boolean; | ||
|
||
@state() selectedHiddenChipsCount = 0; | ||
|
||
@state() selectedVisibleChipsCount = 0; | ||
|
@@ -564,7 +560,6 @@ export class Combobox | |
|
||
async load(): Promise<void> { | ||
setUpLoadableComponent(this); | ||
this.filterItems(this.filterText, false, false); | ||
} | ||
|
||
override willUpdate(changes: PropertyValues<this>): void { | ||
|
@@ -611,16 +606,15 @@ export class Combobox | |
} | ||
|
||
updateHostInteraction(this); | ||
|
||
if (!this.hasUpdated) { | ||
this.refreshSelectionDisplay(); | ||
} | ||
this.refreshSelectionDisplay(); | ||
} | ||
|
||
loaded(): void { | ||
afterConnectDefaultValueSet(this, this.getValue()); | ||
connectFloatingUI(this); | ||
setComponentLoaded(this); | ||
this.updateItems(); | ||
this.filterItems(this.filterText, false, false); | ||
} | ||
|
||
override disconnectedCallback(): void { | ||
|
@@ -658,14 +652,10 @@ export class Combobox | |
|
||
private valueHandler(value: string | string[]): void { | ||
if (!this.internalValueChangeFlag) { | ||
const items = this.getItems(); | ||
if (Array.isArray(value)) { | ||
items.forEach((item) => (item.selected = value.includes(item.value))); | ||
} else if (value) { | ||
items.forEach((item) => (item.selected = value === item.value)); | ||
} else { | ||
items.forEach((item) => (item.selected = false)); | ||
} | ||
this.getItems().forEach((item) => { | ||
item.selected = Array.isArray(value) ? value.includes(item.value) : value === item.value; | ||
}); | ||
|
||
this.updateItems(); | ||
} | ||
} | ||
|
@@ -718,7 +708,9 @@ export class Combobox | |
event: CustomEvent<HTMLCalciteComboboxItemElement["el"]>, | ||
): void { | ||
event.stopPropagation(); | ||
this.updateItems(); | ||
if (this.hasUpdated) { | ||
this.updateItems(); | ||
} | ||
} | ||
|
||
private clearValue(): void { | ||
|
@@ -931,6 +923,7 @@ export class Combobox | |
listContainerEl.style.inlineSize = `${referenceEl.clientWidth}px`; | ||
await this.reposition(true); | ||
} | ||
|
||
private calciteChipCloseHandler(comboboxItem: HTMLCalciteComboboxItemElement["el"]): void { | ||
this.open = false; | ||
|
||
|
@@ -1229,15 +1222,20 @@ export class Combobox | |
return this.filterText === "" ? this.items : this.items.filter((item) => !item.hidden); | ||
} | ||
|
||
private updateItems = debounce((): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we still debounce this in some cases? Like the mutation observer case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could keep an eye out for this. The MO callback kicks in once per batch of mutations, so I don't expect a significant increase in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. We may want to have some internal doc/guidelines on when we should debounce a function and under what circumstances. |
||
private updateItems(): void { | ||
this.items = this.getItems(); | ||
this.groupItems = this.getGroupItems(); | ||
|
||
this.data = this.getData(); | ||
this.groupData = this.getGroupData(); | ||
|
||
this.updateItemProps(); | ||
|
||
this.selectedItems = this.getSelectedItems(); | ||
this.filteredItems = this.getFilteredItems(); | ||
this.needsIcon = this.getNeedsIcon(); | ||
} | ||
|
||
private updateItemProps(): void { | ||
this.items.forEach((item) => { | ||
item.selectionMode = this.selectionMode; | ||
item.scale = this.scale; | ||
|
@@ -1260,7 +1258,7 @@ export class Combobox | |
nextGroupItem.afterEmptyGroup = groupItem.children.length === 0; | ||
} | ||
}); | ||
}, DEBOUNCE.nextTick); | ||
} | ||
|
||
private getData(): ItemData[] { | ||
return this.items.map((item) => ({ | ||
|
@@ -1281,10 +1279,6 @@ export class Combobox | |
})); | ||
} | ||
|
||
private getNeedsIcon(): boolean { | ||
return isSingleLike(this.selectionMode) && this.items.some((item) => item.icon); | ||
} | ||
|
||
private resetText(): void { | ||
if (this.textInput.value) { | ||
this.textInput.value.value = ""; | ||
|
@@ -1308,9 +1302,6 @@ export class Combobox | |
if (existingItem) { | ||
this.toggleSelection(existingItem, true); | ||
} else { | ||
if (!this.isMulti()) { | ||
this.toggleSelection(this.selectedItems[this.selectedItems.length - 1], false); | ||
} | ||
const item = document.createElement( | ||
// TODO: [MIGRATION] If this is dynamically creating a web component, please read the docs: https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-jsx--docs#rendering-jsx-outside-the-component | ||
"calcite-combobox-item", | ||
|
@@ -1319,14 +1310,11 @@ export class Combobox | |
item.heading = value; | ||
item.selected = true; | ||
this.el.prepend(item); | ||
this.resetText(); | ||
this.toggleSelection(item, true); | ||
this.open = true; | ||
if (focus) { | ||
this.setFocus(); | ||
} | ||
this.updateItems(); | ||
this.filterItems(""); | ||
this.open = true; | ||
this.emitComboboxChange(); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice