Skip to content

Commit

Permalink
add comments to focusTrap options and cleanu up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijbet committed Oct 3, 2024
1 parent 7e3dda8 commit 06e68ff
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export class Dialog
connectMessages(this);
connectFocusTrap(this, {
focusTrapOptions: {
// Scrim has it's own close handler, allow it to take over.
clickOutsideDeactivates: false,
escapeDeactivates: (event) => {
if (event.defaultPrevented || this.escapeDisabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,6 @@ describe("calcite-input-date-picker", () => {
}

it("toggles the date picker when clicked", async () => {
const openSpy = await inputDatePicker.spyOnEvent("calciteInputDatePickerOpen");
const closeSpy = await inputDatePicker.spyOnEvent("calciteInputDatePickerClose");
const calendar = await page.find(`calcite-input-date-picker >>> .${CSS.calendarWrapper}`);

expect(await isCalendarVisible(calendar, "start")).toBe(false);
Expand All @@ -454,13 +452,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await startInput.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(1);

expect(await isCalendarVisible(calendar, "start")).toBe(true);

await startInput.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(1);

expect(await isCalendarVisible(calendar, "start")).toBe(false);

Expand All @@ -469,13 +465,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await startInputToggle.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(2);

expect(await isCalendarVisible(calendar, "start")).toBe(true);

await startInputToggle.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(2);

expect(await isCalendarVisible(calendar, "start")).toBe(false);

Expand All @@ -484,13 +478,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await endInput.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(3);

expect(await isCalendarVisible(calendar, "end")).toBe(true);

await endInput.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(3);

expect(await isCalendarVisible(calendar, "end")).toBe(false);

Expand All @@ -499,13 +491,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await endInputToggle.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(4);

expect(await isCalendarVisible(calendar, "end")).toBe(true);

await endInputToggle.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(4);

expect(await isCalendarVisible(calendar, "end")).toBe(false);

Expand All @@ -514,13 +504,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await startInput.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(5);

expect(await isCalendarVisible(calendar, "start")).toBe(true);

await startInputToggle.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(5);

expect(await isCalendarVisible(calendar, "start")).toBe(false);

Expand All @@ -529,13 +517,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await startInputToggle.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(6);

expect(await isCalendarVisible(calendar, "start")).toBe(true);

await startInput.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(6);

expect(await isCalendarVisible(calendar, "start")).toBe(false);

Expand All @@ -544,13 +530,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await endInput.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(7);

expect(await isCalendarVisible(calendar, "end")).toBe(true);

await endInputToggle.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(7);

expect(await isCalendarVisible(calendar, "end")).toBe(false);

Expand All @@ -559,13 +543,11 @@ describe("calcite-input-date-picker", () => {
await resetFocus(page);
await endInputToggle.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(8);

expect(await isCalendarVisible(calendar, "end")).toBe(true);

await endInput.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(8);

expect(await isCalendarVisible(calendar, "end")).toBe(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ export class InputDatePicker
focusTrapEl: el,
focusTrapOptions: {
allowOutsideClick: true,
// Allow outside click and let the popover manager take care of closing the popover.
clickOutsideDeactivates: false,
initialFocus: false,
setReturnFocus: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,45 +933,37 @@ describe("calcite-input-time-picker", () => {

it("toggles the time picker when clicked", async () => {
let popover = await page.find("calcite-input-time-picker >>> calcite-popover");
const openSpy = await inputTimePicker.spyOnEvent("calciteInputTimePickerOpen");
const closeSpy = await inputTimePicker.spyOnEvent("calciteInputTimePickerClose");

expect(await popover.isVisible()).toBe(false);

await inputTimePicker.click();
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(1);
popover = await page.find("calcite-input-time-picker >>> calcite-popover");

expect(await popover.isVisible()).toBe(true);

await inputTimePicker.click();
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(1);
popover = await page.find("calcite-input-time-picker >>> calcite-popover");

expect(await popover.isVisible()).toBe(false);
});

it("toggles the time picker when using arrow down/escape key", async () => {
let popover = await page.find("calcite-input-time-picker >>> calcite-popover");
const openSpy = await inputTimePicker.spyOnEvent("calciteInputTimePickerOpen");
const closeSpy = await inputTimePicker.spyOnEvent("calciteInputTimePickerClose");

expect(await popover.isVisible()).toBe(false);

await inputTimePicker.callMethod("setFocus");
await page.waitForChanges();
await page.keyboard.press("ArrowDown");
await page.waitForChanges();
expect(openSpy).toHaveReceivedEventTimes(1);
popover = await page.find("calcite-input-time-picker >>> calcite-popover");

expect(await popover.isVisible()).toBe(true);

await page.keyboard.press("Escape");
await page.waitForChanges();
expect(closeSpy).toHaveReceivedEventTimes(1);
popover = await page.find("calcite-input-time-picker >>> calcite-popover");

expect(await popover.isVisible()).toBe(false);
Expand Down
1 change: 1 addition & 0 deletions packages/calcite-components/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class Modal
connectMessages(this);
connectFocusTrap(this, {
focusTrapOptions: {
// Scrim has it's own close handler, allow it to take over.
clickOutsideDeactivates: false,
escapeDeactivates: (event) => {
if (event.defaultPrevented || this.escapeDisabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,7 @@ export class Popover
const outsideClick = !path.includes(this.el);
const shouldCloseOnOutsideClick = this.autoClose && outsideClick;

return (
(shouldCloseOnOutsideClick && this.triggerDisabled) ||
(shouldCloseOnOutsideClick && isReferenceElementInPath)
);
return shouldCloseOnOutsideClick && (this.triggerDisabled || isReferenceElementInPath);
},
},
});
Expand Down

0 comments on commit 06e68ff

Please sign in to comment.