Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,7 @@ describe("calcite-input-time-zone", () => {

const timeZoneItem = await page.find("calcite-input-time-zone >>> calcite-combobox-item[selected]");

expect(await timeZoneItem.getProperty("textLabel")).toMatch(
toUserFriendlyName(getCity(testTimeZoneItems[1].name)),
);
expect(await timeZoneItem.getProperty("textLabel")).toBe("Phoenix, United States");
});

it("ignores invalid values", async () => {
Expand All @@ -386,9 +384,7 @@ describe("calcite-input-time-zone", () => {

const timeZoneItem = await page.find("calcite-input-time-zone >>> calcite-combobox-item[selected]");

expect(await timeZoneItem.getProperty("textLabel")).toMatch(
toUserFriendlyName(getCity(testTimeZoneItems[0].name)),
);
expect(await timeZoneItem.getProperty("textLabel")).toBe("Mexico City, Mexico");
});

it("properly sets region label when setting value programmatically", async () => {
Expand All @@ -407,7 +403,7 @@ describe("calcite-input-time-zone", () => {

const timeZoneItem = await page.find("calcite-input-time-zone >>> calcite-combobox-item[selected]");

expect(await timeZoneItem.getProperty("textLabel")).toMatch(toUserFriendlyName(getCity(region)));
expect(await timeZoneItem.getProperty("textLabel")).toBe("New York, United States");
});

it("maps deprecated time zones to aliases", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ export class InputTimeZone
}

loaded(): void {
this.overrideSelectedLabelForRegion(this.open);
this.openChanged();
}

Expand Down Expand Up @@ -357,11 +356,6 @@ export class InputTimeZone

this._value = normalized;
this.selectedTimeZoneItem = timeZoneItem;

if (normalized !== value) {
await this.updateComplete;
this.overrideSelectedLabelForRegion(this.open);
}
}

onLabelClick(): void {
Expand All @@ -378,28 +372,23 @@ export class InputTimeZone
* @param open
* @private
*/
private overrideSelectedLabelForRegion(open: boolean): void {
private overrideSelectedLabelForRegion(): void {
if (this.mode !== "region" || !this.selectedTimeZoneItem) {
return;
}

const { label, metadata } = this.selectedTimeZoneItem;

this.comboboxEl.selectedItems[0].textLabel =
!metadata.country || open
? label
: getSelectedRegionTimeZoneLabel(label, metadata.country, this.messages);
this.comboboxEl.selectedItems[0].textLabel = this.getItemLabel(this.selectedTimeZoneItem);
}

private onComboboxBeforeClose(event: CustomEvent): void {
event.stopPropagation();
this.overrideSelectedLabelForRegion(false);
this.overrideSelectedLabelForRegion();
this.calciteInputTimeZoneBeforeClose.emit();
}

private onComboboxBeforeOpen(event: CustomEvent): void {
event.stopPropagation();
this.overrideSelectedLabelForRegion(true);
this.overrideSelectedLabelForRegion();
this.calciteInputTimeZoneBeforeOpen.emit();
}

Expand Down Expand Up @@ -486,6 +475,14 @@ export class InputTimeZone
return value ? this.normalizer(value) : value;
}

private getItemLabel(item: TimeZoneItem): string {
const selected = this.selectedTimeZoneItem === item;
const { label, metadata } = item;
return !this.open && item.metadata.country && selected
? getSelectedRegionTimeZoneLabel(label, metadata.country, this.messages)
: label;
}

//#endregion

//#region Rendering
Expand Down Expand Up @@ -556,15 +553,15 @@ export class InputTimeZone
{items.map((item) => {
const selected = this.selectedTimeZoneItem === item;
const { label, metadata, value } = item;

const textLabel = this.getItemLabel(item);
return (
<calcite-combobox-item
data-label={label}
description={metadata.country}
key={label}
metadata={metadata}
selected={selected}
textLabel={label}
textLabel={textLabel}
value={value}
>
<span class={CSS.offset} slot="content-end">
Expand Down