@neovici/cosmoz-dropdown 3.2.0 → 3.4.0
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.
- package/dist/use-focus.d.ts +3 -1
- package/dist/use-focus.js +5 -4
- package/dist/use-position.d.ts +1 -1
- package/package.json +2 -2
package/dist/use-focus.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export interface UseFocusOpts {
|
|
2
2
|
disabled?: boolean;
|
|
3
|
-
onFocus
|
|
3
|
+
onFocus?: (focused: boolean) => void;
|
|
4
4
|
}
|
|
5
5
|
export declare const useFocus: ({ disabled, onFocus }: UseFocusOpts) => {
|
|
6
|
+
focused: boolean | undefined;
|
|
6
7
|
active: boolean | undefined;
|
|
7
8
|
setClosed: (closed: boolean) => void;
|
|
8
9
|
onToggle: (e: Event) => void;
|
|
9
10
|
onFocus: (e: FocusEvent) => void;
|
|
10
11
|
};
|
|
11
12
|
export declare const useHostFocus: (host: HTMLElement & UseFocusOpts) => {
|
|
13
|
+
focused: boolean | undefined;
|
|
12
14
|
active: boolean | undefined;
|
|
13
15
|
setClosed: (closed: boolean) => void;
|
|
14
16
|
onToggle: (e: Event) => void;
|
package/dist/use-focus.js
CHANGED
|
@@ -2,14 +2,14 @@ import { useEffect, useState, useCallback } from 'haunted';
|
|
|
2
2
|
import { useMeta } from '@neovici/cosmoz-utils/hooks/use-meta';
|
|
3
3
|
const isFocused = (t) => t.matches(':focus-within');
|
|
4
4
|
export const useFocus = ({ disabled, onFocus }) => {
|
|
5
|
-
const [focusState, setState] = useState(), { focused, closed } = focusState || {},
|
|
5
|
+
const [focusState, setState] = useState(), { focused: _focused, closed } = focusState || {}, focused = _focused && !disabled, meta = useMeta({ closed, onFocus }), setClosed = useCallback((closed) => setState((p) => ({ ...p, closed })), []), onToggle = useCallback((e) => {
|
|
6
6
|
const target = e.currentTarget;
|
|
7
7
|
return isFocused(target)
|
|
8
8
|
? setState((p) => ({ focused: true, closed: !p?.closed }))
|
|
9
9
|
: target.focus();
|
|
10
10
|
}, []);
|
|
11
11
|
useEffect(() => {
|
|
12
|
-
if (!
|
|
12
|
+
if (!focused) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const handler = (e) => {
|
|
@@ -28,9 +28,10 @@ export const useFocus = ({ disabled, onFocus }) => {
|
|
|
28
28
|
};
|
|
29
29
|
document.addEventListener('keydown', handler, true);
|
|
30
30
|
return () => document.removeEventListener('keydown', handler, true);
|
|
31
|
-
}, [
|
|
31
|
+
}, [focused]);
|
|
32
32
|
return {
|
|
33
|
-
|
|
33
|
+
focused,
|
|
34
|
+
active: focused && !closed,
|
|
34
35
|
setClosed,
|
|
35
36
|
onToggle,
|
|
36
37
|
onFocus: useCallback((e) => {
|
package/dist/use-position.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export interface PositionOpts {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const position: ({ host, anchor, placement, confinement, limit, }: PositionOpts) => void;
|
|
13
13
|
interface UsePositionOpts extends Omit<PositionOpts, 'anchor'> {
|
|
14
|
-
anchor?: (() => HTMLElement) | HTMLElement | null;
|
|
14
|
+
anchor?: (() => HTMLElement | null) | HTMLElement | null;
|
|
15
15
|
}
|
|
16
16
|
export declare const usePosition: ({ anchor: anchorage, host, ...thru }: UsePositionOpts) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-dropdown",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "A simple dropdown web component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit-html",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@semantic-release/changelog": "^6.0.0",
|
|
83
83
|
"@semantic-release/git": "^10.0.0",
|
|
84
84
|
"@storybook/storybook-deployer": "^2.8.5",
|
|
85
|
-
"@web/dev-server-storybook": "^0.
|
|
85
|
+
"@web/dev-server-storybook": "^0.7.0",
|
|
86
86
|
"husky": "^8.0.0",
|
|
87
87
|
"semantic-release": "^21.0.0",
|
|
88
88
|
"sinon": "^15.0.0",
|