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

feat: pass eventTarget to onClickOutside #72

Merged
merged 1 commit into from
Oct 13, 2021
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
2 changes: 1 addition & 1 deletion packages/browser/src/click-outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function watchClickOutside(
}
// inform click outside
for (const { settings } of layersToInform) {
settings.onClickOutside!();
settings.onClickOutside!(target);
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const overlapBindConfig = Symbol(`overlap-bind`);
export interface LayerSettings {
overlap: `window` | HTMLElement;
backdrop: `none` | `block` | `hide`;
onClickOutside?: () => void;
onClickOutside?: (target: EventTarget) => void;
onMouseIntersection?: () => void;
onFocusChange?: () => void;
generateElement: boolean;
Expand Down
29 changes: 29 additions & 0 deletions packages/browser/test/click-outside.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,35 @@ describe(`click-outside`, () => {
expect(onClickOutside, `no dispatch for layer click`).to.have.callCount(1);
});

it(`should pass the target element`, async function () {
this.timeout(3000);
const onClickOutside = stub();
const backdrop = createBackdropParts();
const { container, expectQuery } = testDriver.render(
() => `
<div id="root-node" style="width: 100px; height: 100px; background: green;">
<div id="root-inner" style="width: 10px; height: 10px; background: yellow;"></div>
</div>
`
);
const rootLayer = createRoot();
const rootNode = expectQuery(`#root-node`);
const rootInner = expectQuery(`#root-inner`);
rootLayer.element.appendChild(rootNode);
rootLayer.createLayer({ settings: { onClickOutside } });
updateLayers(container, rootLayer, backdrop);

watchClickOutside(container, rootLayer, backdrop);

await click(`#root-node`);

expect(onClickOutside.getCall(0).args, `root target`).to.eql([rootNode]);

await click(`#root-inner`);

expect(onClickOutside.getCall(1).args, `root inner`).to.eql([rootInner]);
});

it(`should not be called when an internal layer is clicked`, async () => {
const onShallowClickOutside = stub();
const onDeepClickOutside = stub();
Expand Down
18 changes: 9 additions & 9 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ The component will generate a new zeejs layer above layer it is rendered in.

**props:**

| name | type | default | required | description |
| --------------------- | ---------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `backdrop` | "none" \| "block" \| "hide" | "none" | false | background behavior; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#backdrop) |
| `overlap` | "window" \| HTMLElement | "window" | false | layer bounds reference |
| `onClickOutside` | () => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |
| name | type | default | required | description |
| --------------------- | ----------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `backdrop` | "none" \| "block" \| "hide" | "none" | false | background behavior; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#backdrop) |
| `overlap` | "window" \| HTMLElement | "window" | false | layer bounds reference |
| `onClickOutside` | (target: EventTarget) => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |

**code example:**

Expand Down Expand Up @@ -154,7 +154,7 @@ The modal primitive display content that is not affected by the scroll of lower
| `backdrop` | "none" \| "block" \| "hide" | "block" | false | background behavior; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#backdrop) |
| `position` | "topLeft" \| "top" \| "topRight" \| "left" \| "center" \| "right" \| "bottomLeft" \| "bottom" \| "bottomRight" | "center" | false | fixed align position |
| `show` | boolean | true | false | flag if the layer should be displayed |
| `onClickOutside` | () => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onClickOutside` | (target: EventTarget) => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |
| `className` | string | "" | false | CSS class name to add to the modal box |
Expand Down Expand Up @@ -187,7 +187,7 @@ The modal primitive display content that is not affected by the scroll of lower
| `matchWidth` | boolean | false | false | force the popover box to be in the width of the anchor |
| `matchHeight` | boolean | false | false | force the popover box to be in the height of the anchor |
| `show` | boolean | true | false | flag if the layer should be displayed |
| `onClickOutside` | () => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onClickOutside` | ((target: EventTarget) => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |
| `onDisplayChange` | (isPositioned: boolean) => void | | false | invoked when the popover is displayed (after positioning) or removed from DOM |
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface LayerProps {
children: ReactNode;
overlap?: `window` | HTMLElement;
backdrop?: `none` | `block` | `hide`;
onClickOutside?: () => void;
onClickOutside?: (target: EventTarget) => void;
onMouseIntersection?: (isInside: boolean) => void;
onFocusChange?: (isFocused: boolean) => void;
}
Expand Down
24 changes: 12 additions & 12 deletions packages/svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ The component will generate a new zeejs layer above layer it is rendered in.

**props:**

| name | type | default | required | description |
| --------------------- | ---------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `backdrop` | "none" \| "block" \| "hide" | "none" | false | background behavior; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#backdrop) |
| `overlap` | "window" \| HTMLElement | "window" | false | layer bounds reference |
| `onClickOutside` | () => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |
| name | type | default | required | description |
| --------------------- | ----------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `backdrop` | "none" \| "block" \| "hide" | "none" | false | background behavior; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#backdrop) |
| `overlap` | "window" \| HTMLElement | "window" | false | layer bounds reference |
| `onClickOutside` | (target: EventTarget) => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |

**code example:**

Expand Down Expand Up @@ -141,10 +141,10 @@ The modal primitive display content that is not affected by the scroll of lower
| `backdrop` | "none" \| "block" \| "hide" | "block" | false | background behavior; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#backdrop) |
| `position` | "topLeft" \| "top" \| "topRight" \| "left" \| "center" \| "right" \| "bottomLeft" \| "bottom" \| "bottomRight" | "center" | false | fixed align position |
| `show` | boolean | true | false | flag if the layer should be displayed |
| `onClickOutside` | () => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onClickOutside` | (target: EventTarget) => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |
| `class` | string | "" | false | CSS class name to add to the modal box |
| `class` | string | "" | false | CSS class name to add to the modal box |
| `style` | React.CSSProperties | {} | false | CSS inline style to add to the modal box |

### `<Tooltip>` component
Expand Down Expand Up @@ -174,9 +174,9 @@ The modal primitive display content that is not affected by the scroll of lower
| `matchWidth` | boolean | false | false | force the popover box to be in the width of the anchor |
| `matchHeight` | boolean | false | false | force the popover box to be in the height of the anchor |
| `show` | boolean | true | false | flag if the layer should be displayed |
| `onClickOutside` | () => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onClickOutside` | (target: EventTarget) => void | | false | invoked on click outside; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#click-outside) |
| `onMouseIntersection` | (isInside: boolean) => void | | false | invoked when mouse leaves or enters layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#mouse-intersection) |
| `onFocusChange` | (isFocused: boolean) => void | | false | invoked when focus is moved into/out of layer; [see docs](https://github.com/idoros/zeejs/blob/master/docs/documentation.md#focus-change) |
| `onDisplayChange` | (isPositioned: boolean) => void | | false | invoked when the popover is displayed (after positioning) or removed from DOM |
| `class` | string | "" | false | CSS class name to add to the popover box |
| `style` | React.CSSProperties | {} | false | CSS inline style to add to the popover box |
| `class` | string | "" | false | CSS class name to add to the popover box |
| `style` | React.CSSProperties | {} | false | CSS inline style to add to the popover box |