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(input-time-zone): ensure beforeOpen/open and beforeClose/close events emit properly #10228

Merged
Merged
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 @@ -53,12 +53,7 @@ describe("calcite-dialog", () => {

describe("openClose", () => {
openClose("calcite-dialog");

describe("initially open", () => {
openClose("calcite-dialog", {
initialToggleValue: true,
});
});
openClose.initial("calcite-dialog");
});

describe("slots", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ describe("calcite-input-time-picker", () => {

describe("openClose", () => {
openClose("calcite-input-time-picker");

describe.skip("initially open", () => {
openClose("calcite-input-time-picker", { initialToggleValue: true });
});
openClose.initial("calcite-input-time-picker");
});

it("when set to readOnly, element still focusable but won't display the controls or allow for changing the value", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
formAssociated,
hidden,
labelable,
openClose,
reflects,
renders,
t9n,
Expand Down Expand Up @@ -128,6 +129,27 @@ describe("calcite-input-time-zone", () => {
t9n(simpleTestProvider);
});

describe("openClose", () => {
openClose(simpleTestProvider);

describe("initially open", () => {
openClose.initial("calcite-input-time-zone", {
beforeContent: async (page) => {
await page.emulateTimezone(testTimeZoneItems[0].name);

// we add the override script this way because `setContent` was already used before this hook, and calling it again will result in an error.
await page.evaluate(
(supportedTimeZoneOverrideHtml) =>
document.body.insertAdjacentHTML("beforeend", supportedTimeZoneOverrideHtml),
overrideSupportedTimeZones(""),
);

await page.waitForChanges();
},
});
});
});

describe("mode", () => {
describe("offset (default)", () => {
describe("selects user's matching time zone offset on initialization", () => {
Expand All @@ -154,7 +176,7 @@ describe("calcite-input-time-zone", () => {
const page = await newE2EPage();
await page.emulateTimezone(testTimeZoneItems[0].name);
await page.setContent(
await overrideSupportedTimeZones(
overrideSupportedTimeZones(
html`<calcite-input-time-zone value="${testTimeZoneItems[1].offset}"></calcite-input-time-zone>`,
),
);
Expand All @@ -172,7 +194,7 @@ describe("calcite-input-time-zone", () => {
const page = await newE2EPage();
await page.emulateTimezone(testTimeZoneItems[0].name);
await page.setContent(
await overrideSupportedTimeZones(html`<calcite-input-time-zone value="9000"></calcite-input-time-zone>`),
overrideSupportedTimeZones(html`<calcite-input-time-zone value="9000"></calcite-input-time-zone>`),
);

const input = await page.find("calcite-input-time-zone");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ export class InputTimeZone
/** When `true`, displays and positions the component. */
@Prop({ mutable: true, reflect: true }) open = false;

@Watch("open")
openChanged(): void {
// we set the property instead of the attribute to ensure open/close events are emitted properly
this.comboboxEl.open = this.open;
}

/**
* Determines the type of positioning to use for the overlaid content.
*
Expand Down Expand Up @@ -487,6 +493,7 @@ export class InputTimeZone
componentDidLoad(): void {
setComponentLoaded(this);
this.overrideSelectedLabelForRegion(this.open);
this.openChanged();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, i'm wondering if its better to call this when there's a ref for the element rather than in componentDidLoad?

I'm not sure it makes a difference in most cases but it just seems more appropriate?

In this case it would be in setComboboxRef

}

componentDidRender(): void {
Expand All @@ -508,7 +515,6 @@ export class InputTimeZone
onCalciteComboboxChange={this.onComboboxChange}
onCalciteComboboxClose={this.onComboboxClose}
onCalciteComboboxOpen={this.onComboboxOpen}
open={this.open}
overlayPositioning={this.overlayPositioning}
placeholder={
this.mode === "name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ describe("calcite-modal", () => {

describe("openClose", () => {
openClose("calcite-modal");

describe("initially open", () => {
openClose("calcite-modal", {
initialToggleValue: true,
});
});
openClose.initial("calcite-modal");
});

describe("slots", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ describe("calcite-sheet properties", () => {

describe("openClose", () => {
openClose("calcite-sheet");

describe("initially open", () => {
openClose("calcite-sheet", {
initialToggleValue: true,
});
});
openClose.initial("calcite-sheet");
});

it("sets custom width correctly", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export type TagAndPage = {
page: E2EPage;
};

export type TagOrHTMLWithBeforeContent = {
tagOrHTML: TagOrHTML;
export type TagOrHTMLWithBeforeContent = WithBeforeContent<{ tagOrHTML: TagOrHTML }>;

export type WithBeforeContent<TestContent> = TestContent & {
/**
* Allows for custom setup of the page.
*
Expand Down
Loading
Loading