@neovici/cosmoz-dropdown 7.4.1 → 7.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -119,7 +119,14 @@ const CosmozDropdownNext = (host) => {
119
119
  useEffect(() => {
120
120
  host.toggleAttribute('opened', !!opened);
121
121
  }, [opened]);
122
- useAutoOpen({ host, popoverRef, openOnHover, openOnFocus, open, close });
122
+ const { scheduleClose, cancelClose } = useAutoOpen({
123
+ host,
124
+ popoverRef,
125
+ openOnHover,
126
+ openOnFocus,
127
+ open,
128
+ close,
129
+ });
123
130
  // With open-on-focus, only open (not toggle) on click to avoid racing
124
131
  // with the focusin handler
125
132
  const handleClick = openOnFocus ? open : toggle;
@@ -139,6 +146,8 @@ const CosmozDropdownNext = (host) => {
139
146
  style="position-area: ${placement}"
140
147
  @toggle=${onToggle}
141
148
  @select=${close}
149
+ @focusout=${scheduleClose}
150
+ @focusin=${cancelClose}
142
151
  ${ref((el) => el && (popoverRef.current = el))}
143
152
  >
144
153
  <slot></slot>
@@ -8,5 +8,8 @@ interface UseAutoOpenOptions {
8
8
  open: () => void;
9
9
  close: () => void;
10
10
  }
11
- export declare const useAutoOpen: ({ host, popoverRef, openOnHover, openOnFocus, open, close, }: UseAutoOpenOptions) => void;
11
+ export declare const useAutoOpen: ({ host, popoverRef, openOnHover, openOnFocus, open, close, }: UseAutoOpenOptions) => {
12
+ scheduleClose: () => void;
13
+ cancelClose: () => void;
14
+ };
12
15
  export {};
@@ -10,8 +10,7 @@ export const useAutoOpen = ({ host, popoverRef, openOnHover, openOnFocus, open,
10
10
  (host.matches(':hover') || popover?.matches(':hover'))) {
11
11
  return;
12
12
  }
13
- if (openOnFocus &&
14
- (host.matches(':focus-within') || popover?.matches(':focus-within'))) {
13
+ if (host.matches(':focus-within') || popover?.matches(':focus-within')) {
15
14
  return;
16
15
  }
17
16
  close();
@@ -45,4 +44,5 @@ export const useAutoOpen = ({ host, popoverRef, openOnHover, openOnFocus, open,
45
44
  host.removeEventListener('focusout', scheduleClose);
46
45
  };
47
46
  }, [openOnFocus, host]);
47
+ return { scheduleClose, cancelClose };
48
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-dropdown",
3
- "version": "7.4.1",
3
+ "version": "7.4.2",
4
4
  "description": "A simple dropdown web component",
5
5
  "keywords": [
6
6
  "lit-html",