@lumx/react 3.6.7 → 3.6.8
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/_internal/types.d.ts +29 -29
- package/index.d.ts +45 -45
- package/index.js +28 -16
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/alert-dialog/AlertDialog.tsx +2 -12
- package/src/components/autocomplete/Autocomplete.test.tsx +1 -1
- package/src/components/autocomplete/AutocompleteMultiple.test.tsx +1 -1
- package/src/components/badge/Badge.test.tsx +1 -1
- package/src/components/button/Button.test.tsx +2 -2
- package/src/components/button/IconButton.test.tsx +1 -1
- package/src/components/chip/Chip.test.tsx +22 -5
- package/src/components/chip/Chip.tsx +9 -5
- package/src/components/date-picker/DatePickerControlled.tsx +5 -4
- package/src/components/generic-block/GenericBlock.test.tsx +9 -9
- package/src/components/grid-column/GridColumn.tsx +32 -34
- package/src/components/icon/Icon.test.tsx +1 -1
- package/src/components/input-helper/InputHelper.test.tsx +1 -1
- package/src/components/link/Link.test.tsx +3 -3
- package/src/components/link-preview/LinkPreview.test.tsx +1 -2
- package/src/components/message/Message.test.tsx +1 -1
- package/src/components/mosaic/Mosaic.tsx +5 -4
- package/src/components/popover/Popover.tsx +13 -20
- package/src/components/select/Select.test.tsx +3 -3
- package/src/components/select/SelectMultiple.stories.tsx +56 -58
- package/src/components/select/SelectMultiple.test.tsx +4 -4
- package/src/components/side-navigation/SideNavigation.test.tsx +2 -2
- package/src/components/slideshow/SlideshowControls.stories.tsx +4 -9
- package/src/components/slideshow/useSlideFocusManagement.tsx +1 -1
- package/src/components/tabs/TabProvider.test.tsx +1 -1
- package/src/components/thumbnail/Thumbnail.stories.tsx +5 -5
- package/src/constants.ts +2 -2
- package/src/stories/decorators/withCombinations.tsx +76 -74
- package/src/utils/date/getFirstDayOfWeek.ts +2 -1
- package/src/utils/date/getMonthCalendar.test.ts +4 -0
- package/src/utils/date/getMonthCalendar.ts +10 -2
- package/src/utils/focus/constants.ts +4 -2
- package/src/utils/focus/getFirstAndLastFocusable.test.ts +19 -19
- package/src/utils/focus/getFocusableElements.test.ts +13 -13
- package/src/utils/type.ts +17 -13
- package/src/utils/utils.test.ts +5 -5
|
@@ -8,13 +8,13 @@ function htmlToElement(html: string): any {
|
|
|
8
8
|
|
|
9
9
|
describe(getFocusableElements.name, () => {
|
|
10
10
|
it('should get empty', () => {
|
|
11
|
-
const element = htmlToElement(
|
|
11
|
+
const element = htmlToElement('<div></div>');
|
|
12
12
|
const focusable = getFocusableElements(element);
|
|
13
13
|
expect(focusable).toEqual([]);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it('should get single item', () => {
|
|
17
|
-
const element = htmlToElement(
|
|
17
|
+
const element = htmlToElement('<div><button /></div>');
|
|
18
18
|
const focusable = getFocusableElements(element);
|
|
19
19
|
expect(focusable).toMatchInlineSnapshot(`
|
|
20
20
|
[
|
|
@@ -25,7 +25,7 @@ describe(getFocusableElements.name, () => {
|
|
|
25
25
|
|
|
26
26
|
describe('match focusable elements', () => {
|
|
27
27
|
it('should match input element', () => {
|
|
28
|
-
const element = htmlToElement(
|
|
28
|
+
const element = htmlToElement('<div><input /></div>');
|
|
29
29
|
const focusable = getFocusableElements(element);
|
|
30
30
|
expect(focusable).toMatchInlineSnapshot(`
|
|
31
31
|
[
|
|
@@ -35,7 +35,7 @@ describe(getFocusableElements.name, () => {
|
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('should match link element', () => {
|
|
38
|
-
const element = htmlToElement(
|
|
38
|
+
const element = htmlToElement('<div><a href="#" /></div>');
|
|
39
39
|
const focusable = getFocusableElements(element);
|
|
40
40
|
expect(focusable).toMatchInlineSnapshot(`
|
|
41
41
|
[
|
|
@@ -47,7 +47,7 @@ describe(getFocusableElements.name, () => {
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
it('should match textarea element', () => {
|
|
50
|
-
const element = htmlToElement(
|
|
50
|
+
const element = htmlToElement('<div><textarea /></div>');
|
|
51
51
|
const focusable = getFocusableElements(element);
|
|
52
52
|
expect(focusable).toMatchInlineSnapshot(`
|
|
53
53
|
[
|
|
@@ -59,7 +59,7 @@ describe(getFocusableElements.name, () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('should match element with tabindex', () => {
|
|
62
|
-
const element = htmlToElement(
|
|
62
|
+
const element = htmlToElement('<div><span tabindex="0" /></div>');
|
|
63
63
|
const focusable = getFocusableElements(element);
|
|
64
64
|
expect(focusable).toMatchInlineSnapshot(`
|
|
65
65
|
[
|
|
@@ -71,7 +71,7 @@ describe(getFocusableElements.name, () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('should keep disabled=false', () => {
|
|
74
|
-
const element = htmlToElement(
|
|
74
|
+
const element = htmlToElement('<div><button disabled="false" /><button /></div>');
|
|
75
75
|
const focusable = getFocusableElements(element);
|
|
76
76
|
expect(focusable).toMatchInlineSnapshot(`
|
|
77
77
|
[
|
|
@@ -84,7 +84,7 @@ describe(getFocusableElements.name, () => {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it('should keep aria-disabled=false', () => {
|
|
87
|
-
const element = htmlToElement(
|
|
87
|
+
const element = htmlToElement('<div><button aria-disabled="false" /><button /></div>');
|
|
88
88
|
const focusable = getFocusableElements(element);
|
|
89
89
|
expect(focusable).toMatchInlineSnapshot(`
|
|
90
90
|
[
|
|
@@ -99,7 +99,7 @@ describe(getFocusableElements.name, () => {
|
|
|
99
99
|
|
|
100
100
|
describe('skip disabled elements', () => {
|
|
101
101
|
it('should skip disabled', () => {
|
|
102
|
-
const element = htmlToElement(
|
|
102
|
+
const element = htmlToElement('<div><button disabled /><button /></div>');
|
|
103
103
|
const focusable = getFocusableElements(element);
|
|
104
104
|
expect(focusable).toMatchInlineSnapshot(`
|
|
105
105
|
[
|
|
@@ -109,7 +109,7 @@ describe(getFocusableElements.name, () => {
|
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
it('should skip aria-disabled', () => {
|
|
112
|
-
const element = htmlToElement(
|
|
112
|
+
const element = htmlToElement('<div><button aria-disabled /><button /></div>');
|
|
113
113
|
const focusable = getFocusableElements(element);
|
|
114
114
|
expect(focusable).toMatchInlineSnapshot(`
|
|
115
115
|
[
|
|
@@ -119,7 +119,7 @@ describe(getFocusableElements.name, () => {
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
it('should skip tabindex=-1', () => {
|
|
122
|
-
const element = htmlToElement(
|
|
122
|
+
const element = htmlToElement('<div><button tabindex="-1" /><button /></div>');
|
|
123
123
|
const focusable = getFocusableElements(element);
|
|
124
124
|
expect(focusable).toMatchInlineSnapshot(`
|
|
125
125
|
[
|
|
@@ -129,7 +129,7 @@ describe(getFocusableElements.name, () => {
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
it('should skip input type hidden', () => {
|
|
132
|
-
const element = htmlToElement(
|
|
132
|
+
const element = htmlToElement('<div><input type="hidden" /><button /></div>');
|
|
133
133
|
const focusable = getFocusableElements(element);
|
|
134
134
|
expect(focusable).toMatchInlineSnapshot(`
|
|
135
135
|
[
|
|
@@ -139,7 +139,7 @@ describe(getFocusableElements.name, () => {
|
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it('should skip hidden input', () => {
|
|
142
|
-
const element = htmlToElement(
|
|
142
|
+
const element = htmlToElement('<div><input hidden /><button /></div>');
|
|
143
143
|
const focusable = getFocusableElements(element);
|
|
144
144
|
expect(focusable).toMatchInlineSnapshot(`
|
|
145
145
|
[
|
package/src/utils/type.ts
CHANGED
|
@@ -81,20 +81,24 @@ export type Predicate<T> = (t: T) => boolean;
|
|
|
81
81
|
* @param component React function component or the component name
|
|
82
82
|
* @return predicate returning true if value is instance of the component
|
|
83
83
|
*/
|
|
84
|
-
export const isComponent =
|
|
85
|
-
|
|
84
|
+
export const isComponent =
|
|
85
|
+
<C>(component: Comp<C, any> | string) =>
|
|
86
|
+
(instance: ReactNode): instance is ReactElement => {
|
|
87
|
+
const componentName = typeof component === 'string' ? component : component.displayName;
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
89
|
+
return (
|
|
90
|
+
!!get(instance, '$$typeof') &&
|
|
91
|
+
NAME_PROPERTIES.some((nameProperty: string): boolean => get(instance, nameProperty) === componentName)
|
|
92
|
+
);
|
|
93
|
+
};
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
96
|
* Similar to `isComponent` but more precise as it's not based on the component `displayName` but on the component function reference.
|
|
95
97
|
*/
|
|
96
|
-
export const isComponentType =
|
|
97
|
-
|
|
98
|
+
export const isComponentType =
|
|
99
|
+
(type: ReactElement['type']) =>
|
|
100
|
+
(node: ReactNode): node is ReactElement =>
|
|
101
|
+
React.isValidElement(node) && node.type === type;
|
|
98
102
|
|
|
99
103
|
/**
|
|
100
104
|
* JS falsy values.
|
|
@@ -131,7 +135,7 @@ export type HasAriaLabelOrLabelledBy<T = string | undefined> = T extends string
|
|
|
131
135
|
export type ComponentRef<C> = C extends keyof JSX.IntrinsicElements
|
|
132
136
|
? JSX.IntrinsicElements[C]['ref']
|
|
133
137
|
: C extends Comp<any, infer T>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
? React.Ref<T>
|
|
139
|
+
: C extends React.JSXElementConstructor<{ ref?: infer R }>
|
|
140
|
+
? R
|
|
141
|
+
: never;
|
package/src/utils/utils.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import partition from 'lodash/partition';
|
|
|
2
2
|
import { partitionMulti } from './partitionMulti';
|
|
3
3
|
import { isInternetExplorer } from './isInternetExplorer';
|
|
4
4
|
|
|
5
|
-
describe(
|
|
5
|
+
describe('partitionMulti', () => {
|
|
6
6
|
it('should act like partition for single predicate', () => {
|
|
7
7
|
const data = [0, 1, 2, 3, 4, 5];
|
|
8
8
|
const isEven = (n: number): boolean => n % 2 === 0;
|
|
@@ -27,21 +27,21 @@ describe(`partitionMulti`, () => {
|
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
describe(
|
|
30
|
+
describe('isInternetExplorer', () => {
|
|
31
31
|
it('should detect IE 10', () => {
|
|
32
|
-
const userAgentIE10 =
|
|
32
|
+
const userAgentIE10 = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)';
|
|
33
33
|
Object.defineProperty(window.navigator, 'userAgent', { value: userAgentIE10, configurable: true });
|
|
34
34
|
expect(isInternetExplorer()).toEqual(true);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
it('should detect IE 11', () => {
|
|
38
|
-
const userAgentIE11 =
|
|
38
|
+
const userAgentIE11 = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
|
|
39
39
|
Object.defineProperty(window.navigator, 'userAgent', { value: userAgentIE11, configurable: true });
|
|
40
40
|
expect(isInternetExplorer()).toEqual(true);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('should not detect IE', () => {
|
|
44
|
-
const userAgentFirefox =
|
|
44
|
+
const userAgentFirefox = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:74.0) Gecko/20100101 Firefox/74.0';
|
|
45
45
|
Object.defineProperty(window.navigator, 'userAgent', { value: userAgentFirefox, configurable: true });
|
|
46
46
|
expect(isInternetExplorer()).toEqual(false);
|
|
47
47
|
});
|