@react-spectrum/datepicker 3.0.0 → 3.1.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.
- package/dist/main.css +1 -1
- package/dist/main.js +336 -17
- package/dist/main.js.map +1 -1
- package/dist/module.js +337 -18
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/DatePicker.tsx +6 -3
- package/src/DateRangePicker.tsx +7 -4
- package/src/Input.tsx +20 -17
- package/src/TimeField.tsx +3 -3
- package/src/index.ts +1 -0
- package/src/styles.css +20 -0
package/src/Input.tsx
CHANGED
|
@@ -37,29 +37,32 @@ function Input(props, ref) {
|
|
|
37
37
|
// not cause a layout shift.
|
|
38
38
|
let [reservePadding, setReservePadding] = useValueEffect(false);
|
|
39
39
|
let onResize = useCallback(() => setReservePadding(function *(reservePadding) {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
if (inputRef.current) {
|
|
41
|
+
if (reservePadding) {
|
|
42
|
+
// Try to collapse padding if the content is clipped.
|
|
43
|
+
if (inputRef.current.scrollWidth > inputRef.current.offsetWidth) {
|
|
44
|
+
let width = inputRef.current.parentElement.offsetWidth;
|
|
45
|
+
yield false;
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// If removing padding causes a layout shift, add it back.
|
|
48
|
+
if (inputRef.current.parentElement.offsetWidth !== width) {
|
|
49
|
+
yield true;
|
|
50
|
+
}
|
|
49
51
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
yield true;
|
|
52
|
+
} else {
|
|
53
|
+
// Try to add padding if the content is not clipped.
|
|
54
|
+
if (inputRef.current.offsetWidth >= inputRef.current.scrollWidth) {
|
|
55
|
+
let width = inputRef.current.parentElement.offsetWidth;
|
|
56
|
+
yield true;
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
// If adding padding does not change the width (i.e. width is constrained), remove it again.
|
|
59
|
+
if (inputRef.current.parentElement.offsetWidth === width) {
|
|
60
|
+
yield false;
|
|
61
|
+
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
65
|
+
|
|
63
66
|
}), [inputRef, setReservePadding]);
|
|
64
67
|
|
|
65
68
|
useLayoutEffect(onResize, [onResize]);
|
package/src/TimeField.tsx
CHANGED
|
@@ -17,14 +17,14 @@ import {Field} from '@react-spectrum/label';
|
|
|
17
17
|
import {FocusableRef} from '@react-types/shared';
|
|
18
18
|
import {Input} from './Input';
|
|
19
19
|
import React, {ReactElement} from 'react';
|
|
20
|
-
import {
|
|
20
|
+
import {SpectrumTimeFieldProps, TimeValue} from '@react-types/datepicker';
|
|
21
21
|
import {useFocusManagerRef} from './utils';
|
|
22
22
|
import {useLocale} from '@react-aria/i18n';
|
|
23
23
|
import {useProviderProps} from '@react-spectrum/provider';
|
|
24
24
|
import {useTimeField} from '@react-aria/datepicker';
|
|
25
25
|
import {useTimeFieldState} from '@react-stately/datepicker';
|
|
26
26
|
|
|
27
|
-
function TimeField<T extends TimeValue>(props:
|
|
27
|
+
function TimeField<T extends TimeValue>(props: SpectrumTimeFieldProps<T>, ref: FocusableRef<HTMLElement>) {
|
|
28
28
|
props = useProviderProps(props);
|
|
29
29
|
let {
|
|
30
30
|
autoFocus,
|
|
@@ -78,5 +78,5 @@ function TimeField<T extends TimeValue>(props: SpectrumTimePickerProps<T>, ref:
|
|
|
78
78
|
* TimeFields allow users to enter and edit time values using a keyboard.
|
|
79
79
|
* Each part of the time is displayed in an individually editable segment.
|
|
80
80
|
*/
|
|
81
|
-
const _TimeField = React.forwardRef(TimeField) as <T extends TimeValue>(props:
|
|
81
|
+
const _TimeField = React.forwardRef(TimeField) as <T extends TimeValue>(props: SpectrumTimeFieldProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
|
|
82
82
|
export {_TimeField as TimeField};
|
package/src/index.ts
CHANGED
|
@@ -16,3 +16,4 @@ export {DatePicker} from './DatePicker';
|
|
|
16
16
|
export {DateRangePicker} from './DateRangePicker';
|
|
17
17
|
export {TimeField} from './TimeField';
|
|
18
18
|
export {DateField} from './DateField';
|
|
19
|
+
export type {SpectrumDateFieldProps, SpectrumDatePickerProps, SpectrumDateRangePickerProps, SpectrumTimeFieldProps} from '@react-types/datepicker';
|
package/src/styles.css
CHANGED
|
@@ -182,3 +182,23 @@
|
|
|
182
182
|
padding: 0 var(--spectrum-calendar-day-padding);
|
|
183
183
|
box-sizing: border-box;
|
|
184
184
|
}
|
|
185
|
+
|
|
186
|
+
@media (forced-colors:active) {
|
|
187
|
+
.react-spectrum-DatePicker-cell:focus {
|
|
188
|
+
forced-color-adjust: none;
|
|
189
|
+
background-color: Highlight;
|
|
190
|
+
color: HighlightText;
|
|
191
|
+
}
|
|
192
|
+
.react-spectrum-DatePicker-cell.is-read-only {
|
|
193
|
+
color: ButtonText;
|
|
194
|
+
&:focus {
|
|
195
|
+
color: HighlightText;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
.react-spectrum-DatePicker-cell.is-placeholder {
|
|
199
|
+
color: ButtonText;
|
|
200
|
+
&:focus {
|
|
201
|
+
color: HighlightText;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|