@acusti/dropdown 0.44.0 → 0.44.1
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/README.md +1 -1
- package/dist/Dropdown.d.ts +25 -3
- package/dist/Dropdown.js +466 -333
- package/dist/Dropdown.js.flow +59 -59
- package/dist/Dropdown.test.js +80 -47
- package/dist/helpers.d.ts +47 -32
- package/dist/helpers.js +35 -36
- package/dist/helpers.js.flow +37 -37
- package/dist/styles.d.ts +14 -13
- package/dist/styles.js +1 -1
- package/dist/styles.js.flow +12 -12
- package/package.json +5 -5
- package/src/Dropdown.tsx +8 -8
- package/src/helpers.ts +1 -1
package/dist/Dropdown.js.flow
CHANGED
|
@@ -5,74 +5,74 @@
|
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import * as React from
|
|
9
|
-
declare type ChildrenTuple = [React.Node, React.Node];
|
|
8
|
+
import * as React from 'react';
|
|
10
9
|
export type Item = {|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
element: HTMLElement | null,
|
|
11
|
+
event: Event | SyntheticEvent<HTMLElement>,
|
|
12
|
+
label: string,
|
|
13
|
+
value: string,
|
|
15
14
|
|};
|
|
16
15
|
export type Props = {|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Boolean indicating if the user can submit a value not already in the
|
|
18
|
+
* dropdown.
|
|
19
|
+
*/
|
|
20
|
+
allowCreate?: boolean,
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Boolean indicating if the user can submit an empty value (i.e. clear
|
|
24
|
+
* the value). Defaults to true.
|
|
25
|
+
*/
|
|
26
|
+
allowEmpty?: boolean,
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Can take a single React element or exactly two renderable children.
|
|
30
|
+
*/
|
|
31
|
+
children: ChildrenTuple | React.Node,
|
|
32
|
+
className?: string,
|
|
33
|
+
disabled?: boolean,
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Group identifier string links dropdowns together into a menu
|
|
37
|
+
* (like macOS top menubar).
|
|
38
|
+
*/
|
|
39
|
+
group?: string,
|
|
40
|
+
hasItems?: boolean,
|
|
41
|
+
isOpenOnMount?: boolean,
|
|
42
|
+
isSearchable?: boolean,
|
|
43
|
+
keepOpenOnSubmit?: boolean,
|
|
44
|
+
label?: string,
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Only usable in conjunction with {isSearchable: true}.
|
|
48
|
+
* Used as search input’s name.
|
|
49
|
+
*/
|
|
50
|
+
name?: string,
|
|
51
|
+
onClick?: (event: SyntheticMouseEvent<HTMLElement>) => mixed,
|
|
52
|
+
onClose?: () => mixed,
|
|
53
|
+
onMouseDown?: (event: SyntheticMouseEvent<HTMLElement>) => mixed,
|
|
54
|
+
onMouseUp?: (event: SyntheticMouseEvent<HTMLElement>) => mixed,
|
|
55
|
+
onOpen?: () => mixed,
|
|
56
|
+
onSubmitItem?: (payload: Item) => void,
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Only usable in conjunction with {isSearchable: true}.
|
|
60
|
+
* Used as search input’s placeholder.
|
|
61
|
+
*/
|
|
62
|
+
placeholder?: string,
|
|
63
|
+
style?: {| [string]: string | number |},
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Only usable in conjunction with {isSearchable: true}.
|
|
67
|
+
* Used as search input’s tabIndex.
|
|
68
|
+
*/
|
|
69
|
+
tabIndex?: number,
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Used as search input’s value if props.isSearchable === true
|
|
73
|
+
* Used to determine if value has changed to avoid triggering onSubmitItem if not
|
|
74
|
+
*/
|
|
75
|
+
value?: string,
|
|
77
76
|
|};
|
|
77
|
+
declare type ChildrenTuple = [React.Node, React.Node];
|
|
78
78
|
declare export default function Dropdown(x: Props): React.Node;
|
package/dist/Dropdown.test.js
CHANGED
|
@@ -8,18 +8,26 @@ afterEach(cleanup);
|
|
|
8
8
|
describe('@acusti/dropdown', () => {
|
|
9
9
|
it('renders its contents as a dropdown menu with an empty button to trigger it when it’s rendered with a single child', async () => {
|
|
10
10
|
const user = userEvent.setup();
|
|
11
|
-
render(
|
|
12
|
-
React.createElement(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
React.createElement(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
render(
|
|
12
|
+
React.createElement(
|
|
13
|
+
Dropdown,
|
|
14
|
+
null,
|
|
15
|
+
React.createElement(
|
|
16
|
+
'ul',
|
|
17
|
+
{ 'data-testid': 'dropdown-list' },
|
|
18
|
+
React.createElement('li', null, '0px'),
|
|
19
|
+
React.createElement('li', null, '4px'),
|
|
20
|
+
React.createElement('li', null, '9px'),
|
|
21
|
+
React.createElement('li', null, '18px'),
|
|
22
|
+
React.createElement('li', null, '36px'),
|
|
23
|
+
React.createElement('li', null, '54px'),
|
|
24
|
+
React.createElement('li', null, '72px'),
|
|
25
|
+
React.createElement('li', null, '144px'),
|
|
26
|
+
React.createElement('li', null, '167px'),
|
|
27
|
+
React.createElement('li', null, '198px'),
|
|
28
|
+
),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
23
31
|
const trigger = screen.getByRole('button');
|
|
24
32
|
expect(trigger.innerHTML).toBe('');
|
|
25
33
|
await user.click(trigger);
|
|
@@ -27,22 +35,30 @@ describe('@acusti/dropdown', () => {
|
|
|
27
35
|
});
|
|
28
36
|
it('renders the first child as a trigger and the second child as a dropdown when given two children', async () => {
|
|
29
37
|
const user = userEvent.setup();
|
|
30
|
-
render(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
React.createElement(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
render(
|
|
39
|
+
React.createElement(
|
|
40
|
+
Dropdown,
|
|
41
|
+
null,
|
|
42
|
+
'File',
|
|
43
|
+
React.createElement(
|
|
44
|
+
'ul',
|
|
45
|
+
{ 'data-testid': 'file-menu' },
|
|
46
|
+
React.createElement('li', null, 'New Window'),
|
|
47
|
+
React.createElement('li', null, 'New Private Window'),
|
|
48
|
+
React.createElement('li', null, 'New Tab'),
|
|
49
|
+
React.createElement('li', null, 'New Empty Tab Group'),
|
|
50
|
+
React.createElement('li', null, 'Open File\u2026'),
|
|
51
|
+
React.createElement('li', null, 'Open Location\u2026'),
|
|
52
|
+
React.createElement('li', { className: 'separator' }),
|
|
53
|
+
React.createElement('li', null, 'Close Window'),
|
|
54
|
+
React.createElement('li', null, 'Close All Window'),
|
|
55
|
+
React.createElement('li', null, 'Close Tab'),
|
|
56
|
+
React.createElement('li', null, 'Save As\u2026'),
|
|
57
|
+
React.createElement('li', { className: 'separator' }),
|
|
58
|
+
React.createElement('li', null, 'Print\u2026'),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
46
62
|
const trigger = screen.getByRole('button');
|
|
47
63
|
expect(trigger.innerHTML).toBe('File');
|
|
48
64
|
await user.click(trigger);
|
|
@@ -54,22 +70,30 @@ describe('@acusti/dropdown', () => {
|
|
|
54
70
|
let openedCount = 0;
|
|
55
71
|
const handleOpen = () => openedCount++;
|
|
56
72
|
const user = userEvent.setup();
|
|
57
|
-
render(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
React.createElement(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
render(
|
|
74
|
+
React.createElement(
|
|
75
|
+
Dropdown,
|
|
76
|
+
{ onClose: handleClose, onOpen: handleOpen },
|
|
77
|
+
'File',
|
|
78
|
+
React.createElement(
|
|
79
|
+
'ul',
|
|
80
|
+
{ 'data-testid': 'file-menu' },
|
|
81
|
+
React.createElement('li', null, 'New Window'),
|
|
82
|
+
React.createElement('li', null, 'New Private Window'),
|
|
83
|
+
React.createElement('li', null, 'New Tab'),
|
|
84
|
+
React.createElement('li', null, 'New Empty Tab Group'),
|
|
85
|
+
React.createElement('li', null, 'Open File\u2026'),
|
|
86
|
+
React.createElement('li', null, 'Open Location\u2026'),
|
|
87
|
+
React.createElement('li', { className: 'separator' }),
|
|
88
|
+
React.createElement('li', null, 'Close Window'),
|
|
89
|
+
React.createElement('li', null, 'Close All Window'),
|
|
90
|
+
React.createElement('li', null, 'Close Tab'),
|
|
91
|
+
React.createElement('li', null, 'Save As\u2026'),
|
|
92
|
+
React.createElement('li', { className: 'separator' }),
|
|
93
|
+
React.createElement('li', null, 'Print\u2026'),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
73
97
|
const trigger = screen.getByRole('button');
|
|
74
98
|
expect(closedCount).toBe(0);
|
|
75
99
|
expect(openedCount).toBe(0);
|
|
@@ -88,8 +112,17 @@ describe('@acusti/dropdown', () => {
|
|
|
88
112
|
let openedCount = 0;
|
|
89
113
|
const handleOpen = () => openedCount++;
|
|
90
114
|
const user = userEvent.setup();
|
|
91
|
-
render(
|
|
92
|
-
React.createElement(
|
|
115
|
+
render(
|
|
116
|
+
React.createElement(
|
|
117
|
+
Dropdown,
|
|
118
|
+
{ isOpenOnMount: true, onClose: handleClose, onOpen: handleOpen },
|
|
119
|
+
React.createElement(
|
|
120
|
+
'p',
|
|
121
|
+
{ 'data-testid': 'dropdown-body' },
|
|
122
|
+
'this is the dropdown contents',
|
|
123
|
+
),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
93
126
|
const trigger = screen.getByRole('button');
|
|
94
127
|
expect(screen.getByTestId('dropdown-body')).toBeTruthy();
|
|
95
128
|
expect(openedCount).toBe(1);
|
|
@@ -99,4 +132,4 @@ describe('@acusti/dropdown', () => {
|
|
|
99
132
|
expect(screen.queryByTestId('dropdown-body')).toBe(null);
|
|
100
133
|
});
|
|
101
134
|
});
|
|
102
|
-
//# sourceMappingURL=Dropdown.test.js.map
|
|
135
|
+
//# sourceMappingURL=Dropdown.test.js.map
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,32 +1,47 @@
|
|
|
1
|
-
export declare const ITEM_SELECTOR =
|
|
2
|
-
export declare const getItemElements: (
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
export declare const ITEM_SELECTOR = '[data-ukt-item], [data-ukt-value]';
|
|
2
|
+
export declare const getItemElements: (
|
|
3
|
+
dropdownElement: HTMLElement | null,
|
|
4
|
+
) => HTMLCollection | NodeListOf<Element> | null;
|
|
5
|
+
export declare const getActiveItemElement: (
|
|
6
|
+
dropdownElement: HTMLElement | null,
|
|
7
|
+
) => HTMLElement | null;
|
|
8
|
+
export declare const setActiveItem: ({
|
|
9
|
+
dropdownElement,
|
|
10
|
+
element,
|
|
11
|
+
index,
|
|
12
|
+
indexAddend,
|
|
13
|
+
isExactMatch,
|
|
14
|
+
text,
|
|
15
|
+
}:
|
|
16
|
+
| {
|
|
17
|
+
dropdownElement: HTMLElement;
|
|
18
|
+
element: HTMLElement;
|
|
19
|
+
index?: null;
|
|
20
|
+
indexAddend?: null;
|
|
21
|
+
isExactMatch?: null;
|
|
22
|
+
text?: null;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
dropdownElement: HTMLElement;
|
|
26
|
+
element?: null;
|
|
27
|
+
index: number;
|
|
28
|
+
indexAddend?: null;
|
|
29
|
+
isExactMatch?: null;
|
|
30
|
+
text?: null;
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
dropdownElement: HTMLElement;
|
|
34
|
+
element?: null;
|
|
35
|
+
index?: null;
|
|
36
|
+
indexAddend: number;
|
|
37
|
+
isExactMatch?: null;
|
|
38
|
+
text?: null;
|
|
39
|
+
}
|
|
40
|
+
| {
|
|
41
|
+
dropdownElement: HTMLElement;
|
|
42
|
+
element?: null;
|
|
43
|
+
index?: null;
|
|
44
|
+
indexAddend?: null;
|
|
45
|
+
isExactMatch?: boolean;
|
|
46
|
+
text: string;
|
|
47
|
+
}) => void;
|
package/dist/helpers.js
CHANGED
|
@@ -2,20 +2,16 @@ import { getBestMatch } from '@acusti/matchmaking';
|
|
|
2
2
|
import { BODY_SELECTOR } from './styles.js';
|
|
3
3
|
export const ITEM_SELECTOR = `[data-ukt-item], [data-ukt-value]`;
|
|
4
4
|
export const getItemElements = (dropdownElement) => {
|
|
5
|
-
if (!dropdownElement)
|
|
6
|
-
return null;
|
|
5
|
+
if (!dropdownElement) return null;
|
|
7
6
|
const bodyElement = dropdownElement.querySelector(BODY_SELECTOR);
|
|
8
|
-
if (!bodyElement)
|
|
9
|
-
return null;
|
|
7
|
+
if (!bodyElement) return null;
|
|
10
8
|
let items = bodyElement.querySelectorAll(ITEM_SELECTOR);
|
|
11
|
-
if (items.length)
|
|
12
|
-
return items;
|
|
9
|
+
if (items.length) return items;
|
|
13
10
|
// If no items found via [data-ukt-item] or [data-ukt-value] selector,
|
|
14
11
|
// use first instance of multiple children found
|
|
15
12
|
items = bodyElement.children;
|
|
16
13
|
while (items.length === 1) {
|
|
17
|
-
if (items[0].children == null)
|
|
18
|
-
break;
|
|
14
|
+
if (items[0].children == null) break;
|
|
19
15
|
items = items[0].children;
|
|
20
16
|
}
|
|
21
17
|
// If unable to find an element with more than one child, treat direct child as items
|
|
@@ -25,8 +21,7 @@ export const getItemElements = (dropdownElement) => {
|
|
|
25
21
|
return items;
|
|
26
22
|
};
|
|
27
23
|
export const getActiveItemElement = (dropdownElement) => {
|
|
28
|
-
if (!dropdownElement)
|
|
29
|
-
return null;
|
|
24
|
+
if (!dropdownElement) return null;
|
|
30
25
|
return dropdownElement.querySelector('[data-ukt-active]');
|
|
31
26
|
};
|
|
32
27
|
const clearItemElementsState = (itemElements) => {
|
|
@@ -36,40 +31,45 @@ const clearItemElementsState = (itemElements) => {
|
|
|
36
31
|
}
|
|
37
32
|
});
|
|
38
33
|
};
|
|
39
|
-
export const setActiveItem = ({
|
|
34
|
+
export const setActiveItem = ({
|
|
35
|
+
dropdownElement,
|
|
36
|
+
element,
|
|
37
|
+
index,
|
|
38
|
+
indexAddend,
|
|
39
|
+
isExactMatch,
|
|
40
|
+
text,
|
|
41
|
+
}) => {
|
|
40
42
|
const items = getItemElements(dropdownElement);
|
|
41
|
-
if (!items)
|
|
42
|
-
return;
|
|
43
|
+
if (!items) return;
|
|
43
44
|
const itemElements = Array.from(items);
|
|
44
|
-
if (!itemElements.length)
|
|
45
|
-
return;
|
|
45
|
+
if (!itemElements.length) return;
|
|
46
46
|
const lastIndex = itemElements.length - 1;
|
|
47
|
-
const currentActiveIndex = itemElements.findIndex((itemElement) =>
|
|
47
|
+
const currentActiveIndex = itemElements.findIndex((itemElement) =>
|
|
48
|
+
itemElement.hasAttribute('data-ukt-active'),
|
|
49
|
+
);
|
|
48
50
|
let nextActiveIndex = currentActiveIndex;
|
|
49
51
|
if (typeof index === 'number') {
|
|
50
52
|
// Negative index means count back from the end
|
|
51
53
|
nextActiveIndex = index < 0 ? itemElements.length + index : index;
|
|
52
54
|
}
|
|
53
55
|
if (element) {
|
|
54
|
-
nextActiveIndex = itemElements.findIndex(
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
nextActiveIndex = itemElements.findIndex(
|
|
57
|
+
(itemElement) => itemElement === element,
|
|
58
|
+
);
|
|
59
|
+
} else if (typeof indexAddend === 'number') {
|
|
57
60
|
// If there’s no currentActiveIndex and we are handling -1, start at lastIndex
|
|
58
61
|
if (currentActiveIndex === -1 && indexAddend === -1) {
|
|
59
62
|
nextActiveIndex = lastIndex;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
63
|
+
} else {
|
|
62
64
|
nextActiveIndex += indexAddend;
|
|
63
65
|
}
|
|
64
66
|
// Keep it within the bounds of the items list
|
|
65
67
|
if (nextActiveIndex < 0) {
|
|
66
68
|
nextActiveIndex = 0;
|
|
67
|
-
}
|
|
68
|
-
else if (nextActiveIndex > lastIndex) {
|
|
69
|
+
} else if (nextActiveIndex > lastIndex) {
|
|
69
70
|
nextActiveIndex = lastIndex;
|
|
70
71
|
}
|
|
71
|
-
}
|
|
72
|
-
else if (typeof text === 'string') {
|
|
72
|
+
} else if (typeof text === 'string') {
|
|
73
73
|
// If text is empty, clear existing active items and early return
|
|
74
74
|
if (!text) {
|
|
75
75
|
clearItemElementsState(itemElements);
|
|
@@ -78,19 +78,19 @@ export const setActiveItem = ({ dropdownElement, element, index, indexAddend, is
|
|
|
78
78
|
const itemTexts = itemElements.map((itemElement) => itemElement.innerText);
|
|
79
79
|
if (isExactMatch) {
|
|
80
80
|
const textToCompare = text.toLowerCase();
|
|
81
|
-
nextActiveIndex = itemTexts.findIndex((itemText) =>
|
|
81
|
+
nextActiveIndex = itemTexts.findIndex((itemText) =>
|
|
82
|
+
itemText.toLowerCase().startsWith(textToCompare),
|
|
83
|
+
);
|
|
82
84
|
// If isExactMatch is required and no exact match was found, clear active items
|
|
83
85
|
if (nextActiveIndex === -1) {
|
|
84
86
|
clearItemElementsState(itemElements);
|
|
85
87
|
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
+
} else {
|
|
88
89
|
const bestMatch = getBestMatch({ items: itemTexts, text });
|
|
89
90
|
nextActiveIndex = itemTexts.findIndex((itemText) => itemText === bestMatch);
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
|
-
if (nextActiveIndex === -1 || nextActiveIndex === currentActiveIndex)
|
|
93
|
-
return;
|
|
93
|
+
if (nextActiveIndex === -1 || nextActiveIndex === currentActiveIndex) return;
|
|
94
94
|
// Clear any existing active dropdown body item state
|
|
95
95
|
clearItemElementsState(itemElements);
|
|
96
96
|
const nextActiveItem = items[nextActiveIndex];
|
|
@@ -100,11 +100,11 @@ export const setActiveItem = ({ dropdownElement, element, index, indexAddend, is
|
|
|
100
100
|
let { parentElement } = nextActiveItem;
|
|
101
101
|
let scrollableParent = null;
|
|
102
102
|
while (!scrollableParent && parentElement && parentElement !== dropdownElement) {
|
|
103
|
-
const isScrollable =
|
|
103
|
+
const isScrollable =
|
|
104
|
+
parentElement.scrollHeight > parentElement.clientHeight + 15;
|
|
104
105
|
if (isScrollable) {
|
|
105
106
|
scrollableParent = parentElement;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
107
|
+
} else {
|
|
108
108
|
parentElement = parentElement.parentElement;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -118,8 +118,7 @@ export const setActiveItem = ({ dropdownElement, element, index, indexAddend, is
|
|
|
118
118
|
// Item isn’t fully visible; adjust scrollTop to put item within closest edge
|
|
119
119
|
if (isAboveTop) {
|
|
120
120
|
scrollTop -= parentRect.top - itemRect.top;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
121
|
+
} else {
|
|
123
122
|
scrollTop += itemRect.bottom - parentRect.bottom;
|
|
124
123
|
}
|
|
125
124
|
scrollableParent.scrollTop = scrollTop;
|
|
@@ -127,4 +126,4 @@ export const setActiveItem = ({ dropdownElement, element, index, indexAddend, is
|
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
};
|
|
130
|
-
//# sourceMappingURL=helpers.js.map
|
|
129
|
+
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.flow
CHANGED
|
@@ -5,45 +5,45 @@
|
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare export var ITEM_SELECTOR:
|
|
8
|
+
declare export var ITEM_SELECTOR: '[data-ukt-item], [data-ukt-value]';
|
|
9
9
|
declare export var getItemElements: (
|
|
10
|
-
|
|
11
|
-
) => NodeListOf<Element> |
|
|
10
|
+
dropdownElement: HTMLElement | null,
|
|
11
|
+
) => HTMLCollection | NodeListOf<Element> | null;
|
|
12
12
|
declare export var getActiveItemElement: (
|
|
13
|
-
|
|
13
|
+
dropdownElement: HTMLElement | null,
|
|
14
14
|
) => HTMLElement | null;
|
|
15
15
|
declare export var setActiveItem: (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
16
|
+
x:
|
|
17
|
+
| {|
|
|
18
|
+
dropdownElement: HTMLElement,
|
|
19
|
+
element: HTMLElement,
|
|
20
|
+
index?: null,
|
|
21
|
+
indexAddend?: null,
|
|
22
|
+
isExactMatch?: null,
|
|
23
|
+
text?: null,
|
|
24
|
+
|}
|
|
25
|
+
| {|
|
|
26
|
+
dropdownElement: HTMLElement,
|
|
27
|
+
element?: null,
|
|
28
|
+
index: number,
|
|
29
|
+
indexAddend?: null,
|
|
30
|
+
isExactMatch?: null,
|
|
31
|
+
text?: null,
|
|
32
|
+
|}
|
|
33
|
+
| {|
|
|
34
|
+
dropdownElement: HTMLElement,
|
|
35
|
+
element?: null,
|
|
36
|
+
index?: null,
|
|
37
|
+
indexAddend: number,
|
|
38
|
+
isExactMatch?: null,
|
|
39
|
+
text?: null,
|
|
40
|
+
|}
|
|
41
|
+
| {|
|
|
42
|
+
dropdownElement: HTMLElement,
|
|
43
|
+
element?: null,
|
|
44
|
+
index?: null,
|
|
45
|
+
indexAddend?: null,
|
|
46
|
+
isExactMatch?: boolean,
|
|
47
|
+
text: string,
|
|
48
|
+
|},
|
|
49
49
|
) => void;
|
package/dist/styles.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export declare const ROOT_CLASS_NAME =
|
|
2
|
-
export declare const ROOT_SELECTOR =
|
|
3
|
-
export declare const BODY_CLASS_NAME =
|
|
4
|
-
export declare const LABEL_CLASS_NAME =
|
|
5
|
-
export declare const LABEL_TEXT_CLASS_NAME =
|
|
6
|
-
export declare const TRIGGER_CLASS_NAME =
|
|
7
|
-
export declare const BODY_SELECTOR =
|
|
8
|
-
export declare const LABEL_SELECTOR =
|
|
9
|
-
export declare const LABEL_TEXT_SELECTOR =
|
|
10
|
-
export declare const TRIGGER_SELECTOR =
|
|
11
|
-
export declare const BODY_MAX_HEIGHT_VAR =
|
|
12
|
-
export declare const BODY_MAX_WIDTH_VAR =
|
|
13
|
-
export declare const STYLES =
|
|
1
|
+
export declare const ROOT_CLASS_NAME = 'uktdropdown';
|
|
2
|
+
export declare const ROOT_SELECTOR = '.uktdropdown';
|
|
3
|
+
export declare const BODY_CLASS_NAME = 'uktdropdown-body';
|
|
4
|
+
export declare const LABEL_CLASS_NAME = 'uktdropdown-label';
|
|
5
|
+
export declare const LABEL_TEXT_CLASS_NAME = 'uktdropdown-label-text';
|
|
6
|
+
export declare const TRIGGER_CLASS_NAME = 'uktdropdown-trigger';
|
|
7
|
+
export declare const BODY_SELECTOR = '.uktdropdown-body';
|
|
8
|
+
export declare const LABEL_SELECTOR = '.uktdropdown-label';
|
|
9
|
+
export declare const LABEL_TEXT_SELECTOR = '.uktdropdown-label-text';
|
|
10
|
+
export declare const TRIGGER_SELECTOR = '.uktdropdown-trigger';
|
|
11
|
+
export declare const BODY_MAX_HEIGHT_VAR = '--uktdd-body-max-height';
|
|
12
|
+
export declare const BODY_MAX_WIDTH_VAR = '--uktdd-body-max-width';
|
|
13
|
+
export declare const STYLES =
|
|
14
|
+
'\n:root {\n --uktdd-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;\n --uktdd-body-bg-color: #fff;\n --uktdd-body-bg-color-hover: rgb(105,162,249);\n --uktdd-body-color-hover: #fff;\n --uktdd-body-buffer: 10px;\n --uktdd-body-max-height: calc(100vh - var(--uktdd-body-buffer));\n --uktdd-body-max-width: calc(100vw - var(--uktdd-body-buffer));\n --uktdd-body-pad-bottom: 9px;\n --uktdd-body-pad-left: 12px;\n --uktdd-body-pad-right: 12px;\n --uktdd-body-pad-top: 9px;\n --uktdd-label-pad-right: 10px;\n}\n.uktdropdown,\n.uktdropdown-trigger {\n font-family: var(--uktdd-font-family);\n}\n.uktdropdown {\n position: relative;\n display: inline-block;\n}\n.uktdropdown.disabled {\n pointer-events: none;\n}\n.uktdropdown > * {\n cursor: default;\n}\n.uktdropdown-label {\n display: flex;\n}\n.uktdropdown-label-text {\n padding-right: var(--uktdd-label-pad-right);\n}\n.uktdropdown-body {\n box-sizing: border-box;\n position: absolute;\n top: 100%;\n max-height: var(--uktdd-body-max-height);\n min-height: 50px;\n max-width: var(--uktdd-body-max-width);\n min-width: 100%;\n overflow: auto;\n z-index: 2;\n padding: var(--uktdd-body-pad-top) var(--uktdd-body-pad-right) var(--uktdd-body-pad-bottom) var(--uktdd-body-pad-left);\n background-color: var(--uktdd-body-bg-color);\n box-shadow: 0 8px 18px rgba(0,0,0,0.25);\n}\n.uktdropdown-body.calculating-position {\n visibility: hidden;\n}\n.uktdropdown-body.out-of-bounds-bottom:not(.out-of-bounds-top) {\n top: auto;\n bottom: 100%;\n}\n.uktdropdown-body.out-of-bounds-right:not(.out-of-bounds-left) {\n left: auto;\n right: 0px;\n}\n.uktdropdown-label + .uktdropdown-body {\n left: auto;\n right: 0;\n}\n.uktdropdown-body.has-items {\n user-select: none;\n}\n.uktdropdown-body [data-ukt-active] {\n background-color: var(--uktdd-body-bg-color-hover);\n color: var(--uktdd-body-color-hover);\n}\n';
|