@indico-data/design-system 3.6.3 → 3.7.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/lib/components/truncate/Truncate.d.ts +1 -1
- package/lib/components/truncate/types.d.ts +2 -3
- package/lib/index.d.ts +3 -4
- package/lib/index.esm.js +22 -3
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +22 -3
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/forms/date/datePicker/DatePicker.tsx +26 -1
- package/src/components/truncate/Truncate.stories.tsx +7 -7
- package/src/components/truncate/Truncate.tsx +4 -4
- package/src/components/truncate/__tests__/Truncate.test.tsx +2 -2
- package/src/components/truncate/types.ts +2 -3
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import { DatePickerProps } from './types';
|
|
|
4
4
|
import { getCommonProps } from './contants';
|
|
5
5
|
import { TimePicker } from '../../timePicker/TimePicker';
|
|
6
6
|
import { Col, Row } from '../../../grid';
|
|
7
|
+
import { useEffect, useRef } from 'react';
|
|
7
8
|
|
|
8
9
|
export const DatePicker = (props: DatePickerProps) => {
|
|
9
10
|
const {
|
|
@@ -84,9 +85,33 @@ export const DatePicker = (props: DatePickerProps) => {
|
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
const finalProps = { ...commonProps, ...rest, ...modeProps };
|
|
88
|
+
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
89
|
+
|
|
90
|
+
// Disable tab focus on all date picker elements
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
const disableTabFocus = () => {
|
|
93
|
+
if (wrapperRef.current) {
|
|
94
|
+
const focusableElements = wrapperRef.current.querySelectorAll(
|
|
95
|
+
'button, input, select, textarea, a, [tabindex]:not([tabindex="-1"])',
|
|
96
|
+
);
|
|
97
|
+
focusableElements.forEach((element) => {
|
|
98
|
+
(element as HTMLElement).tabIndex = -1;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Run immediately and set up observer for dynamic elements
|
|
104
|
+
disableTabFocus();
|
|
105
|
+
const observer = new MutationObserver(disableTabFocus);
|
|
106
|
+
if (wrapperRef.current) {
|
|
107
|
+
observer.observe(wrapperRef.current, { childList: true, subtree: true });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return () => observer.disconnect();
|
|
111
|
+
}, []);
|
|
87
112
|
|
|
88
113
|
return (
|
|
89
|
-
<div className="date-picker-wrapper">
|
|
114
|
+
<div className="date-picker-wrapper" tabIndex={-1} ref={wrapperRef}>
|
|
90
115
|
{hasTimePicker && (
|
|
91
116
|
<div className="time-picker-wrapper">
|
|
92
117
|
<Row align="center">
|
|
@@ -13,7 +13,7 @@ const meta: Meta<typeof Truncate> = {
|
|
|
13
13
|
),
|
|
14
14
|
],
|
|
15
15
|
argTypes: {
|
|
16
|
-
|
|
16
|
+
children: {
|
|
17
17
|
required: true,
|
|
18
18
|
control: 'text',
|
|
19
19
|
table: {
|
|
@@ -43,7 +43,7 @@ type Story = StoryObj<TruncateProps>;
|
|
|
43
43
|
export const Default: Story = {
|
|
44
44
|
args: {
|
|
45
45
|
numLines: 1,
|
|
46
|
-
|
|
46
|
+
children: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.',
|
|
47
47
|
},
|
|
48
48
|
render: (args) => <Truncate {...args} />,
|
|
49
49
|
};
|
|
@@ -51,7 +51,7 @@ export const Default: Story = {
|
|
|
51
51
|
export const NoTruncate: Story = {
|
|
52
52
|
args: {
|
|
53
53
|
numLines: 1,
|
|
54
|
-
|
|
54
|
+
children: 'No truncate',
|
|
55
55
|
},
|
|
56
56
|
render: (args) => <Truncate {...args} />,
|
|
57
57
|
};
|
|
@@ -59,7 +59,7 @@ export const NoTruncate: Story = {
|
|
|
59
59
|
export const WithNumLines: Story = {
|
|
60
60
|
args: {
|
|
61
61
|
numLines: 2,
|
|
62
|
-
|
|
62
|
+
children: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.',
|
|
63
63
|
},
|
|
64
64
|
render: (args) => <Truncate {...args} />,
|
|
65
65
|
};
|
|
@@ -71,7 +71,7 @@ export const WithTooltipOptions: Story = {
|
|
|
71
71
|
place: 'right',
|
|
72
72
|
width: '150px',
|
|
73
73
|
},
|
|
74
|
-
|
|
74
|
+
children: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.',
|
|
75
75
|
},
|
|
76
76
|
render: (args) => <Truncate {...args} />,
|
|
77
77
|
};
|
|
@@ -82,7 +82,7 @@ export const NoTooltip: Story = {
|
|
|
82
82
|
tooltipOptions: {
|
|
83
83
|
disabled: true,
|
|
84
84
|
},
|
|
85
|
-
|
|
85
|
+
children: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.',
|
|
86
86
|
},
|
|
87
87
|
render: (args) => <Truncate {...args} />,
|
|
88
88
|
};
|
|
@@ -93,7 +93,7 @@ export const TruncateWithTooltipWidth: Story = {
|
|
|
93
93
|
tooltipOptions: {
|
|
94
94
|
width: 'calc(100% - 40px)',
|
|
95
95
|
},
|
|
96
|
-
|
|
96
|
+
children:
|
|
97
97
|
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.',
|
|
98
98
|
},
|
|
99
99
|
render: (args) => <Truncate {...args} />,
|
|
@@ -6,8 +6,8 @@ import classNames from 'classnames';
|
|
|
6
6
|
|
|
7
7
|
export const Truncate = ({
|
|
8
8
|
numLines = 1,
|
|
9
|
-
truncateString,
|
|
10
9
|
tooltipOptions = {},
|
|
10
|
+
children,
|
|
11
11
|
...rest
|
|
12
12
|
}: TruncateProps) => {
|
|
13
13
|
const [isTruncated, setIsTruncated] = useState(false);
|
|
@@ -47,11 +47,11 @@ export const Truncate = ({
|
|
|
47
47
|
})}
|
|
48
48
|
{...rest}
|
|
49
49
|
>
|
|
50
|
-
{
|
|
50
|
+
{children}
|
|
51
51
|
</span>
|
|
52
|
-
{isTruncated &&
|
|
52
|
+
{isTruncated && children && !tooltipOptions.disabled && (
|
|
53
53
|
<Tooltip {...tooltipOptions} id={id}>
|
|
54
|
-
{
|
|
54
|
+
{children}
|
|
55
55
|
</Tooltip>
|
|
56
56
|
)}
|
|
57
57
|
</div>
|
|
@@ -25,7 +25,7 @@ describe('Truncate', () => {
|
|
|
25
25
|
|
|
26
26
|
// Only way to test is by checking testid, validated this works in app
|
|
27
27
|
it('shows truncated state when content overflows', () => {
|
|
28
|
-
render(<Truncate
|
|
28
|
+
render(<Truncate>This is a very long text that should be truncated</Truncate>);
|
|
29
29
|
|
|
30
30
|
// Now we can use exact IDs instead of regex
|
|
31
31
|
expect(screen.getByTestId('truncate-test-id-truncated')).toBeInTheDocument();
|
|
@@ -42,7 +42,7 @@ describe('Truncate', () => {
|
|
|
42
42
|
value: 200,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
render(<Truncate
|
|
45
|
+
render(<Truncate>Short text</Truncate>);
|
|
46
46
|
|
|
47
47
|
// Now we can use exact IDs
|
|
48
48
|
expect(screen.getByTestId('truncate-test-id-not-truncated')).toBeInTheDocument();
|
|
@@ -3,9 +3,8 @@ import { TooltipProps } from '../tooltip/Tooltip';
|
|
|
3
3
|
export interface TruncateProps {
|
|
4
4
|
/** The number of lines to truncate the text to. If left blank, it will default to 1 line. */
|
|
5
5
|
numLines?: number;
|
|
6
|
-
/** The string to truncate. This value will also be displayed in the tooltip when the text is truncated. */
|
|
7
|
-
truncateString: string;
|
|
8
6
|
/** The options for the tooltip. If `disabled` is `true`, the tooltip will not be shown. If left blank, the tooltip will be shown by default. This is particularly useful if you want to set the width of the tooltip to something other than the default `max-content`. */
|
|
9
7
|
tooltipOptions?: Partial<TooltipProps> & { disabled?: boolean };
|
|
10
|
-
|
|
8
|
+
/** The children to display. This will be displayed in the truncate component. */
|
|
9
|
+
children: React.ReactNode;
|
|
11
10
|
}
|