@wordpress/components 28.4.0 → 28.5.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/CHANGELOG.md +31 -1
- package/build/autocomplete/autocompleter-ui.js +2 -0
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/base-control/styles/base-control-styles.js +8 -8
- package/build/base-control/styles/base-control-styles.js.map +1 -1
- package/build/border-control/styles.js +18 -24
- package/build/border-control/styles.js.map +1 -1
- package/build/color-palette/index.js +1 -1
- package/build/color-palette/index.js.map +1 -1
- package/build/custom-select-control/index.js +37 -14
- package/build/custom-select-control/index.js.map +1 -1
- package/build/custom-select-control/types.js.map +1 -1
- package/build/custom-select-control-v2/styles.js +9 -9
- package/build/custom-select-control-v2/styles.js.map +1 -1
- package/build/date-time/index.js +0 -7
- package/build/date-time/index.js.map +1 -1
- package/build/date-time/time/index.js +66 -38
- package/build/date-time/time/index.js.map +1 -1
- package/build/date-time/time/styles.js +11 -11
- package/build/date-time/time/styles.js.map +1 -1
- package/build/date-time/{time-input → time/time-input}/index.js +7 -7
- package/build/date-time/time/time-input/index.js.map +1 -0
- package/build/dropdown-menu-v2/styles.js +14 -14
- package/build/dropdown-menu-v2/styles.js.map +1 -1
- package/build/form-toggle/index.js +24 -24
- package/build/form-toggle/index.js.map +1 -1
- package/build/guide/index.js +2 -0
- package/build/guide/index.js.map +1 -1
- package/build/heading/types.js.map +1 -1
- package/build/modal/index.js +18 -11
- package/build/modal/index.js.map +1 -1
- package/build/query-controls/index.js +1 -1
- package/build/query-controls/index.js.map +1 -1
- package/build/radio-control/index.js +35 -8
- package/build/radio-control/index.js.map +1 -1
- package/build/radio-control/types.js.map +1 -1
- package/build/select-control/index.js +20 -8
- package/build/select-control/index.js.map +1 -1
- package/build/select-control/types.js.map +1 -1
- package/build/text-control/index.js +1 -0
- package/build/text-control/index.js.map +1 -1
- package/build/toggle-control/index.js +27 -25
- package/build/toggle-control/index.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/component.js +6 -1
- package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option/component.js +6 -1
- package/build/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-icon/component.js +14 -14
- package/build/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
- package/build/tooltip/index.js +12 -1
- package/build/tooltip/index.js.map +1 -1
- package/build/tree-select/index.js +1 -2
- package/build/tree-select/index.js.map +1 -1
- package/build/utils/config-values.js +6 -0
- package/build/utils/config-values.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +2 -0
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/base-control/styles/base-control-styles.js +8 -8
- package/build-module/base-control/styles/base-control-styles.js.map +1 -1
- package/build-module/border-control/styles.js +13 -23
- package/build-module/border-control/styles.js.map +1 -1
- package/build-module/color-palette/index.js +1 -1
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/custom-select-control/index.js +38 -14
- package/build-module/custom-select-control/index.js.map +1 -1
- package/build-module/custom-select-control/types.js.map +1 -1
- package/build-module/custom-select-control-v2/styles.js +9 -9
- package/build-module/custom-select-control-v2/styles.js.map +1 -1
- package/build-module/date-time/index.js +1 -2
- package/build-module/date-time/index.js.map +1 -1
- package/build-module/date-time/time/index.js +66 -38
- package/build-module/date-time/time/index.js.map +1 -1
- package/build-module/date-time/time/styles.js +11 -11
- package/build-module/date-time/time/styles.js.map +1 -1
- package/build-module/date-time/{time-input → time/time-input}/index.js +7 -7
- package/build-module/date-time/time/time-input/index.js.map +1 -0
- package/build-module/dropdown-menu-v2/styles.js +14 -14
- package/build-module/dropdown-menu-v2/styles.js.map +1 -1
- package/build-module/form-toggle/index.js +23 -22
- package/build-module/form-toggle/index.js.map +1 -1
- package/build-module/guide/index.js +2 -0
- package/build-module/guide/index.js.map +1 -1
- package/build-module/heading/types.js.map +1 -1
- package/build-module/modal/index.js +17 -11
- package/build-module/modal/index.js.map +1 -1
- package/build-module/query-controls/index.js +1 -1
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/radio-control/index.js +36 -10
- package/build-module/radio-control/index.js.map +1 -1
- package/build-module/radio-control/types.js.map +1 -1
- package/build-module/select-control/index.js +20 -8
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/select-control/types.js.map +1 -1
- package/build-module/text-control/index.js +1 -0
- package/build-module/text-control/index.js.map +1 -1
- package/build-module/toggle-control/index.js +26 -24
- package/build-module/toggle-control/index.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/component.js +6 -1
- package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option/component.js +6 -1
- package/build-module/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js +14 -14
- package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
- package/build-module/tooltip/index.js +13 -2
- package/build-module/tooltip/index.js.map +1 -1
- package/build-module/tree-select/index.js +1 -2
- package/build-module/tree-select/index.js.map +1 -1
- package/build-module/utils/config-values.js +6 -0
- package/build-module/utils/config-values.js.map +1 -1
- package/build-style/style-rtl.css +60 -24
- package/build-style/style.css +60 -24
- package/build-types/autocomplete/autocompleter-ui.d.ts.map +1 -1
- package/build-types/border-control/styles.d.ts.map +1 -1
- package/build-types/button/stories/e2e/index.story.d.ts.map +1 -1
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-palette/styles.d.ts +2 -2
- package/build-types/color-picker/styles.d.ts +3 -1
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/custom-select-control/index.d.ts +2 -2
- package/build-types/custom-select-control/index.d.ts.map +1 -1
- package/build-types/custom-select-control/stories/index.story.d.ts +3 -3
- package/build-types/custom-select-control/stories/index.story.d.ts.map +1 -1
- package/build-types/custom-select-control/types.d.ts +7 -7
- package/build-types/custom-select-control/types.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/styles.d.ts +16 -28
- package/build-types/custom-select-control-v2/styles.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +2 -2
- package/build-types/date-time/index.d.ts +1 -2
- package/build-types/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/stories/time.story.d.ts +5 -0
- package/build-types/date-time/stories/time.story.d.ts.map +1 -1
- package/build-types/date-time/time/index.d.ts +3 -0
- package/build-types/date-time/time/index.d.ts.map +1 -1
- package/build-types/date-time/time/styles.d.ts.map +1 -1
- package/build-types/date-time/{time-input → time/time-input}/index.d.ts +1 -1
- package/build-types/date-time/time/time-input/index.d.ts.map +1 -0
- package/build-types/date-time/time/time-input/test/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2/styles.d.ts +24 -42
- package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -1
- package/build-types/form-toggle/index.d.ts +2 -5
- package/build-types/form-toggle/index.d.ts.map +1 -1
- package/build-types/guide/index.d.ts.map +1 -1
- package/build-types/heading/component.d.ts +1 -1
- package/build-types/heading/types.d.ts +1 -1
- package/build-types/heading/types.d.ts.map +1 -1
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
- package/build-types/palette-edit/styles.d.ts +2 -2
- package/build-types/query-controls/index.d.ts.map +1 -1
- package/build-types/radio-control/index.d.ts.map +1 -1
- package/build-types/radio-control/stories/index.story.d.ts +1 -0
- package/build-types/radio-control/stories/index.story.d.ts.map +1 -1
- package/build-types/radio-control/test/index.d.ts +2 -0
- package/build-types/radio-control/test/index.d.ts.map +1 -0
- package/build-types/radio-control/types.d.ts +4 -0
- package/build-types/radio-control/types.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts +4 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/stories/index.story.d.ts +9 -3
- package/build-types/select-control/stories/index.story.d.ts.map +1 -1
- package/build-types/select-control/types.d.ts +27 -27
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/tabs/styles.d.ts +8 -14
- package/build-types/tabs/styles.d.ts.map +1 -1
- package/build-types/text-control/index.d.ts +1 -0
- package/build-types/text-control/index.d.ts.map +1 -1
- package/build-types/toggle-control/index.d.ts +3 -9
- package/build-types/toggle-control/index.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/component.d.ts +6 -1
- package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts +6 -1
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts +14 -14
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/build-types/tooltip/test/utils/index.d.ts +1 -5
- package/build-types/tooltip/test/utils/index.d.ts.map +1 -1
- package/build-types/tree-select/index.d.ts +1 -1
- package/build-types/tree-select/index.d.ts.map +1 -1
- package/build-types/utils/config-values.d.ts +6 -0
- package/package.json +20 -20
- package/src/alignment-matrix-control/test/index.tsx +1 -3
- package/src/autocomplete/autocompleter-ui.tsx +2 -0
- package/src/autocomplete/style.scss +0 -6
- package/src/base-control/styles/base-control-styles.ts +1 -1
- package/src/border-control/styles.ts +0 -5
- package/src/button/stories/e2e/index.story.tsx +103 -21
- package/src/button/style.scss +49 -21
- package/src/button/test/index.tsx +18 -40
- package/src/circular-option-picker/test/index.tsx +1 -4
- package/src/color-palette/index.tsx +22 -20
- package/src/composite/legacy/test/index.tsx +2 -18
- package/src/custom-select-control/index.tsx +55 -25
- package/src/custom-select-control/test/index.tsx +47 -30
- package/src/custom-select-control/types.ts +7 -7
- package/src/custom-select-control-v2/styles.ts +7 -6
- package/src/custom-select-control-v2/test/index.tsx +15 -19
- package/src/date-time/index.ts +1 -2
- package/src/date-time/stories/time.story.tsx +17 -0
- package/src/date-time/time/index.tsx +46 -16
- package/src/date-time/time/styles.ts +1 -0
- package/src/date-time/{time-input → time/time-input}/index.tsx +9 -9
- package/src/dropdown-menu-v2/styles.ts +18 -17
- package/src/dropdown-menu-v2/test/index.tsx +1 -4
- package/src/font-size-picker/test/index.tsx +50 -43
- package/src/form-toggle/index.tsx +23 -21
- package/src/guide/index.tsx +2 -0
- package/src/heading/types.ts +1 -4
- package/src/modal/index.tsx +21 -20
- package/src/placeholder/style.scss +11 -2
- package/src/query-controls/index.tsx +5 -1
- package/src/radio-control/index.tsx +48 -7
- package/src/radio-control/stories/index.story.tsx +23 -0
- package/src/radio-control/style.scss +26 -2
- package/src/radio-control/test/index.tsx +274 -0
- package/src/radio-control/types.ts +4 -0
- package/src/select-control/README.md +8 -1
- package/src/select-control/index.tsx +33 -22
- package/src/select-control/test/select-control.tsx +148 -4
- package/src/select-control/types.ts +70 -65
- package/src/tab-panel/test/index.tsx +1 -8
- package/src/tabs/test/index.tsx +68 -84
- package/src/text-control/README.md +1 -0
- package/src/text-control/index.tsx +1 -0
- package/src/text-control/style.scss +5 -0
- package/src/toggle-control/README.md +9 -0
- package/src/toggle-control/index.tsx +25 -22
- package/src/toggle-control/style.scss +2 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +6 -6
- package/src/toggle-group-control/test/index.tsx +0 -6
- package/src/toggle-group-control/toggle-group-control/README.md +13 -1
- package/src/toggle-group-control/toggle-group-control/component.tsx +6 -1
- package/src/toggle-group-control/toggle-group-control-option/README.md +6 -1
- package/src/toggle-group-control/toggle-group-control-option/component.tsx +6 -1
- package/src/toggle-group-control/toggle-group-control-option-icon/README.md +1 -1
- package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +14 -14
- package/src/tooltip/index.tsx +15 -2
- package/src/tooltip/test/index.tsx +0 -5
- package/src/tooltip/test/utils/index.tsx +5 -5
- package/src/tree-select/index.tsx +1 -2
- package/src/utils/config-values.js +6 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/date-time/time-input/index.js.map +0 -1
- package/build-module/date-time/time-input/index.js.map +0 -1
- package/build-types/date-time/stories/time-input.story.d.ts +0 -12
- package/build-types/date-time/stories/time-input.story.d.ts.map +0 -1
- package/build-types/date-time/time-input/index.d.ts.map +0 -1
- package/build-types/date-time/time-input/test/index.d.ts.map +0 -1
- package/src/date-time/stories/time-input.story.tsx +0 -36
- /package/build-types/date-time/{time-input → time/time-input}/test/index.d.ts +0 -0
- /package/src/date-time/{time-input → time/time-input}/test/index.tsx +0 -0
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
validateInputElementTarget,
|
|
33
33
|
} from '../utils';
|
|
34
34
|
import { TIMEZONELESS_FORMAT } from '../constants';
|
|
35
|
-
import { TimeInput } from '
|
|
35
|
+
import { TimeInput } from './time-input';
|
|
36
36
|
|
|
37
37
|
const VALID_DATE_ORDERS = [ 'dmy', 'mdy', 'ymd' ];
|
|
38
38
|
|
|
@@ -77,10 +77,28 @@ export function TimePicker( {
|
|
|
77
77
|
);
|
|
78
78
|
}, [ currentTime ] );
|
|
79
79
|
|
|
80
|
+
const monthOptions = [
|
|
81
|
+
{ value: '01', label: __( 'January' ) },
|
|
82
|
+
{ value: '02', label: __( 'February' ) },
|
|
83
|
+
{ value: '03', label: __( 'March' ) },
|
|
84
|
+
{ value: '04', label: __( 'April' ) },
|
|
85
|
+
{ value: '05', label: __( 'May' ) },
|
|
86
|
+
{ value: '06', label: __( 'June' ) },
|
|
87
|
+
{ value: '07', label: __( 'July' ) },
|
|
88
|
+
{ value: '08', label: __( 'August' ) },
|
|
89
|
+
{ value: '09', label: __( 'September' ) },
|
|
90
|
+
{ value: '10', label: __( 'October' ) },
|
|
91
|
+
{ value: '11', label: __( 'November' ) },
|
|
92
|
+
{ value: '12', label: __( 'December' ) },
|
|
93
|
+
] as const;
|
|
94
|
+
|
|
80
95
|
const { day, month, year, minutes, hours } = useMemo(
|
|
81
96
|
() => ( {
|
|
82
97
|
day: format( date, 'dd' ),
|
|
83
|
-
month: format(
|
|
98
|
+
month: format(
|
|
99
|
+
date,
|
|
100
|
+
'MM'
|
|
101
|
+
) as ( typeof monthOptions )[ number ][ 'value' ],
|
|
84
102
|
year: format( date, 'yyyy' ),
|
|
85
103
|
minutes: format( date, 'mm' ),
|
|
86
104
|
hours: format( date, 'HH' ),
|
|
@@ -146,20 +164,7 @@ export function TimePicker( {
|
|
|
146
164
|
__next40pxDefaultSize
|
|
147
165
|
__nextHasNoMarginBottom
|
|
148
166
|
value={ month }
|
|
149
|
-
options={
|
|
150
|
-
{ value: '01', label: __( 'January' ) },
|
|
151
|
-
{ value: '02', label: __( 'February' ) },
|
|
152
|
-
{ value: '03', label: __( 'March' ) },
|
|
153
|
-
{ value: '04', label: __( 'April' ) },
|
|
154
|
-
{ value: '05', label: __( 'May' ) },
|
|
155
|
-
{ value: '06', label: __( 'June' ) },
|
|
156
|
-
{ value: '07', label: __( 'July' ) },
|
|
157
|
-
{ value: '08', label: __( 'August' ) },
|
|
158
|
-
{ value: '09', label: __( 'September' ) },
|
|
159
|
-
{ value: '10', label: __( 'October' ) },
|
|
160
|
-
{ value: '11', label: __( 'November' ) },
|
|
161
|
-
{ value: '12', label: __( 'December' ) },
|
|
162
|
-
] }
|
|
167
|
+
options={ monthOptions }
|
|
163
168
|
onChange={ ( value ) => {
|
|
164
169
|
const newDate = setMonth( date, Number( value ) - 1 );
|
|
165
170
|
setDate( newDate );
|
|
@@ -252,4 +257,29 @@ export function TimePicker( {
|
|
|
252
257
|
);
|
|
253
258
|
}
|
|
254
259
|
|
|
260
|
+
/**
|
|
261
|
+
* A component to input a time.
|
|
262
|
+
*
|
|
263
|
+
* Values are passed as an object in 24-hour format (`{ hours: number, minutes: number }`).
|
|
264
|
+
*
|
|
265
|
+
* ```jsx
|
|
266
|
+
* import { TimePicker } from '@wordpress/components';
|
|
267
|
+
* import { useState } from '@wordpress/element';
|
|
268
|
+
*
|
|
269
|
+
* const MyTimeInput = () => {
|
|
270
|
+
* const [ time, setTime ] = useState( { hours: 13, minutes: 30 } );
|
|
271
|
+
*
|
|
272
|
+
* return (
|
|
273
|
+
* <TimePicker.TimeInput
|
|
274
|
+
* value={ time }
|
|
275
|
+
* onChange={ setTime }
|
|
276
|
+
* label="Time"
|
|
277
|
+
* />
|
|
278
|
+
* );
|
|
279
|
+
* };
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
TimePicker.TimeInput = TimeInput;
|
|
283
|
+
Object.assign( TimePicker.TimeInput, { displayName: 'TimePicker.TimeInput' } );
|
|
284
|
+
|
|
255
285
|
export default TimePicker;
|
|
@@ -62,6 +62,7 @@ export const HoursInput = styled( NumberControl )`
|
|
|
62
62
|
export const TimeSeparator = styled.span`
|
|
63
63
|
border-top: ${ CONFIG.borderWidth } solid ${ COLORS.gray[ 700 ] };
|
|
64
64
|
border-bottom: ${ CONFIG.borderWidth } solid ${ COLORS.gray[ 700 ] };
|
|
65
|
+
font-size: ${ CONFIG.fontSize };
|
|
65
66
|
line-height: calc(
|
|
66
67
|
${ CONFIG.controlHeight } - ${ CONFIG.borderWidth } * 2
|
|
67
68
|
);
|
|
@@ -18,20 +18,20 @@ import {
|
|
|
18
18
|
HoursInput,
|
|
19
19
|
MinutesInput,
|
|
20
20
|
Fieldset,
|
|
21
|
-
} from '../
|
|
22
|
-
import { HStack } from '
|
|
23
|
-
import Button from '
|
|
24
|
-
import ButtonGroup from '
|
|
21
|
+
} from '../styles';
|
|
22
|
+
import { HStack } from '../../../h-stack';
|
|
23
|
+
import Button from '../../../button';
|
|
24
|
+
import ButtonGroup from '../../../button-group';
|
|
25
25
|
import {
|
|
26
26
|
from12hTo24h,
|
|
27
27
|
from24hTo12h,
|
|
28
28
|
buildPadInputStateReducer,
|
|
29
29
|
validateInputElementTarget,
|
|
30
|
-
} from '
|
|
31
|
-
import type { TimeInputProps } from '
|
|
32
|
-
import type { InputChangeCallback } from '
|
|
33
|
-
import { useControlledValue } from '
|
|
34
|
-
import BaseControl from '
|
|
30
|
+
} from '../../utils';
|
|
31
|
+
import type { TimeInputProps } from '../../types';
|
|
32
|
+
import type { InputChangeCallback } from '../../../input-control/types';
|
|
33
|
+
import { useControlledValue } from '../../../utils';
|
|
34
|
+
import BaseControl from '../../../base-control';
|
|
35
35
|
|
|
36
36
|
export function TimeInput( {
|
|
37
37
|
value: valueProp,
|
|
@@ -101,23 +101,23 @@ export const DropdownMenu = styled( Ariakit.Menu )<
|
|
|
101
101
|
outline: 2px solid transparent !important;
|
|
102
102
|
|
|
103
103
|
/* Animation */
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
104
|
+
&[data-open] {
|
|
105
|
+
@media not ( prefers-reduced-motion ) {
|
|
106
|
+
animation-duration: ${ ANIMATION_PARAMS.DURATION };
|
|
107
|
+
animation-timing-function: ${ ANIMATION_PARAMS.EASING };
|
|
108
|
+
will-change: transform, opacity;
|
|
109
|
+
/* Default animation.*/
|
|
110
|
+
animation-name: ${ slideDownAndFade };
|
|
111
|
+
&[data-side='left'] {
|
|
112
|
+
animation-name: ${ slideLeftAndFade };
|
|
113
|
+
}
|
|
114
|
+
&[data-side='up'] {
|
|
115
|
+
animation-name: ${ slideUpAndFade };
|
|
116
|
+
}
|
|
117
|
+
&[data-side='right'] {
|
|
118
|
+
animation-name: ${ slideRightAndFade };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
121
|
}
|
|
122
122
|
`;
|
|
123
123
|
|
|
@@ -344,6 +344,7 @@ export const DropdownMenuItemHelpText = styled( Truncate )`
|
|
|
344
344
|
font-size: ${ font( 'helpText.fontSize' ) };
|
|
345
345
|
line-height: 16px;
|
|
346
346
|
color: ${ COLORS.gray[ '700' ] };
|
|
347
|
+
word-break: break-all;
|
|
347
348
|
|
|
348
349
|
[data-active-item]:not( [data-focus-visible] ) *:not( ${ DropdownMenu } ) &,
|
|
349
350
|
[aria-disabled='true'] *:not( ${ DropdownMenu } ) & {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
|
-
import { press, click, hover,
|
|
5
|
+
import { press, click, hover, type } from '@ariakit/test';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -128,7 +128,6 @@ describe( 'DropdownMenu', () => {
|
|
|
128
128
|
} );
|
|
129
129
|
|
|
130
130
|
// Move focus on the toggle
|
|
131
|
-
await sleep();
|
|
132
131
|
await press.Tab();
|
|
133
132
|
|
|
134
133
|
expect( toggleButton ).toHaveFocus();
|
|
@@ -159,7 +158,6 @@ describe( 'DropdownMenu', () => {
|
|
|
159
158
|
} );
|
|
160
159
|
|
|
161
160
|
// Move focus on the toggle
|
|
162
|
-
await sleep();
|
|
163
161
|
await press.Tab();
|
|
164
162
|
|
|
165
163
|
expect( toggleButton ).toHaveFocus();
|
|
@@ -915,7 +913,6 @@ describe( 'DropdownMenu', () => {
|
|
|
915
913
|
|
|
916
914
|
// The outer button can be focused by pressing tab. Doing so will cause
|
|
917
915
|
// the DropdownMenu to close.
|
|
918
|
-
await sleep();
|
|
919
916
|
await press.Tab();
|
|
920
917
|
expect( outerButton ).toBeInTheDocument();
|
|
921
918
|
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { screen, fireEvent } from '@testing-library/react';
|
|
5
5
|
import userEvent from '@testing-library/user-event';
|
|
6
|
+
import { render } from '@ariakit/test/react';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
@@ -44,7 +45,9 @@ describe( 'FontSizePicker', () => {
|
|
|
44
45
|
async ( { value, expectedValue } ) => {
|
|
45
46
|
const user = userEvent.setup();
|
|
46
47
|
const onChange = jest.fn();
|
|
47
|
-
render(
|
|
48
|
+
await render(
|
|
49
|
+
<FontSizePicker value={ value } onChange={ onChange } />
|
|
50
|
+
);
|
|
48
51
|
const input = screen.getByLabelText( 'Custom' );
|
|
49
52
|
await user.clear( input );
|
|
50
53
|
await user.type( input, '80' );
|
|
@@ -63,7 +66,7 @@ describe( 'FontSizePicker', () => {
|
|
|
63
66
|
async ( { firstFontSize, expectedValue } ) => {
|
|
64
67
|
const user = userEvent.setup();
|
|
65
68
|
const onChange = jest.fn();
|
|
66
|
-
render(
|
|
69
|
+
await render(
|
|
67
70
|
<FontSizePicker
|
|
68
71
|
fontSizes={ [ { slug: 'slug', size: firstFontSize } ] }
|
|
69
72
|
onChange={ onChange }
|
|
@@ -115,7 +118,7 @@ describe( 'FontSizePicker', () => {
|
|
|
115
118
|
|
|
116
119
|
it( 'displays a select control', async () => {
|
|
117
120
|
const user = userEvent.setup();
|
|
118
|
-
render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
121
|
+
await render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
119
122
|
await user.click(
|
|
120
123
|
screen.getByRole( 'combobox', { name: 'Font size' } )
|
|
121
124
|
);
|
|
@@ -137,8 +140,8 @@ describe( 'FontSizePicker', () => {
|
|
|
137
140
|
{ value: '3px', expectedLabel: 'Size Custom' },
|
|
138
141
|
] )(
|
|
139
142
|
'displays $expectedLabel as label when value is $value',
|
|
140
|
-
( { value, expectedLabel } ) => {
|
|
141
|
-
render(
|
|
143
|
+
async ( { value, expectedLabel } ) => {
|
|
144
|
+
await render(
|
|
142
145
|
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
143
146
|
);
|
|
144
147
|
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
@@ -161,7 +164,7 @@ describe( 'FontSizePicker', () => {
|
|
|
161
164
|
async ( { option, value, expectedArguments } ) => {
|
|
162
165
|
const user = userEvent.setup();
|
|
163
166
|
const onChange = jest.fn();
|
|
164
|
-
render(
|
|
167
|
+
await render(
|
|
165
168
|
<FontSizePicker
|
|
166
169
|
fontSizes={ fontSizes }
|
|
167
170
|
value={ value }
|
|
@@ -219,7 +222,7 @@ describe( 'FontSizePicker', () => {
|
|
|
219
222
|
|
|
220
223
|
it( 'displays a select control', async () => {
|
|
221
224
|
const user = userEvent.setup();
|
|
222
|
-
render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
225
|
+
await render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
223
226
|
await user.click(
|
|
224
227
|
screen.getByRole( 'combobox', { name: 'Font size' } )
|
|
225
228
|
);
|
|
@@ -241,8 +244,8 @@ describe( 'FontSizePicker', () => {
|
|
|
241
244
|
{ value: '8px', option: 'Tiny' },
|
|
242
245
|
] )(
|
|
243
246
|
'defaults to $option when value is $value',
|
|
244
|
-
( { value, option } ) => {
|
|
245
|
-
render(
|
|
247
|
+
async ( { value, option } ) => {
|
|
248
|
+
await render(
|
|
246
249
|
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
247
250
|
);
|
|
248
251
|
expect(
|
|
@@ -260,8 +263,8 @@ describe( 'FontSizePicker', () => {
|
|
|
260
263
|
{ value: '3px', expectedLabel: 'Size Custom' },
|
|
261
264
|
] )(
|
|
262
265
|
'displays $expectedLabel as label when value is $value',
|
|
263
|
-
( { value, expectedLabel } ) => {
|
|
264
|
-
render(
|
|
266
|
+
async ( { value, expectedLabel } ) => {
|
|
267
|
+
await render(
|
|
265
268
|
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
266
269
|
);
|
|
267
270
|
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
@@ -302,7 +305,7 @@ describe( 'FontSizePicker', () => {
|
|
|
302
305
|
async ( { option, value, expectedArguments } ) => {
|
|
303
306
|
const user = userEvent.setup();
|
|
304
307
|
const onChange = jest.fn();
|
|
305
|
-
render(
|
|
308
|
+
await render(
|
|
306
309
|
<FontSizePicker
|
|
307
310
|
fontSizes={ fontSizes }
|
|
308
311
|
value={ value }
|
|
@@ -353,8 +356,8 @@ describe( 'FontSizePicker', () => {
|
|
|
353
356
|
},
|
|
354
357
|
];
|
|
355
358
|
|
|
356
|
-
it( 'displays a toggle group control with t-shirt sizes', () => {
|
|
357
|
-
render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
359
|
+
it( 'displays a toggle group control with t-shirt sizes', async () => {
|
|
360
|
+
await render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
358
361
|
const options = screen.getAllByRole( 'radio' );
|
|
359
362
|
expect( options ).toHaveLength( 5 );
|
|
360
363
|
expect( options[ 0 ] ).toHaveTextContent( 'S' );
|
|
@@ -375,8 +378,8 @@ describe( 'FontSizePicker', () => {
|
|
|
375
378
|
{ value: '40px', expectedLabel: 'Size Gigantosaurus' },
|
|
376
379
|
] )(
|
|
377
380
|
'displays $expectedLabel as label when value is $value',
|
|
378
|
-
( { value, expectedLabel } ) => {
|
|
379
|
-
render(
|
|
381
|
+
async ( { value, expectedLabel } ) => {
|
|
382
|
+
await render(
|
|
380
383
|
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
381
384
|
);
|
|
382
385
|
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
@@ -386,7 +389,7 @@ describe( 'FontSizePicker', () => {
|
|
|
386
389
|
it( 'calls onChange when a font size is selected', async () => {
|
|
387
390
|
const user = userEvent.setup();
|
|
388
391
|
const onChange = jest.fn();
|
|
389
|
-
render(
|
|
392
|
+
await render(
|
|
390
393
|
<FontSizePicker fontSizes={ fontSizes } onChange={ onChange } />
|
|
391
394
|
);
|
|
392
395
|
await user.click( screen.getByRole( 'radio', { name: 'Medium' } ) );
|
|
@@ -422,8 +425,8 @@ describe( 'FontSizePicker', () => {
|
|
|
422
425
|
},
|
|
423
426
|
];
|
|
424
427
|
|
|
425
|
-
it( 'displays a toggle group control with t-shirt sizes', () => {
|
|
426
|
-
render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
428
|
+
it( 'displays a toggle group control with t-shirt sizes', async () => {
|
|
429
|
+
await render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
427
430
|
const options = screen.getAllByRole( 'radio' );
|
|
428
431
|
expect( options ).toHaveLength( 4 );
|
|
429
432
|
expect( options[ 0 ] ).toHaveTextContent( 'S' );
|
|
@@ -447,8 +450,8 @@ describe( 'FontSizePicker', () => {
|
|
|
447
450
|
},
|
|
448
451
|
] )(
|
|
449
452
|
'displays $expectedLabel as label when value is $value',
|
|
450
|
-
( { value, expectedLabel } ) => {
|
|
451
|
-
render(
|
|
453
|
+
async ( { value, expectedLabel } ) => {
|
|
454
|
+
await render(
|
|
452
455
|
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
453
456
|
);
|
|
454
457
|
expect( screen.getByLabelText( expectedLabel ) ).toBeVisible();
|
|
@@ -471,7 +474,7 @@ describe( 'FontSizePicker', () => {
|
|
|
471
474
|
async ( { radio, expectedArguments } ) => {
|
|
472
475
|
const user = userEvent.setup();
|
|
473
476
|
const onChange = jest.fn();
|
|
474
|
-
render(
|
|
477
|
+
await render(
|
|
475
478
|
<FontSizePicker
|
|
476
479
|
fontSizes={ fontSizes }
|
|
477
480
|
onChange={ onChange }
|
|
@@ -490,8 +493,8 @@ describe( 'FontSizePicker', () => {
|
|
|
490
493
|
} );
|
|
491
494
|
|
|
492
495
|
function commonToggleGroupTests( fontSizes: FontSize[] ) {
|
|
493
|
-
it( 'defaults to M when value is 16px', () => {
|
|
494
|
-
render(
|
|
496
|
+
it( 'defaults to M when value is 16px', async () => {
|
|
497
|
+
await render(
|
|
495
498
|
<FontSizePicker
|
|
496
499
|
fontSizes={ fontSizes }
|
|
497
500
|
value={ fontSizes[ 0 ].size }
|
|
@@ -504,8 +507,8 @@ describe( 'FontSizePicker', () => {
|
|
|
504
507
|
|
|
505
508
|
test.each( [ undefined, '' ] )(
|
|
506
509
|
'has no selection when value is %p',
|
|
507
|
-
( value ) => {
|
|
508
|
-
render(
|
|
510
|
+
async ( value ) => {
|
|
511
|
+
await render(
|
|
509
512
|
<FontSizePicker fontSizes={ fontSizes } value={ value } />
|
|
510
513
|
);
|
|
511
514
|
expect( screen.getByRole( 'radiogroup' ) ).toBeVisible();
|
|
@@ -520,7 +523,7 @@ describe( 'FontSizePicker', () => {
|
|
|
520
523
|
it( 'shows custom input when Custom is selected', async () => {
|
|
521
524
|
const user = userEvent.setup();
|
|
522
525
|
const onChange = jest.fn();
|
|
523
|
-
render(
|
|
526
|
+
await render(
|
|
524
527
|
<FontSizePicker fontSizes={ fontSizes } onChange={ onChange } />
|
|
525
528
|
);
|
|
526
529
|
await user.click(
|
|
@@ -535,13 +538,15 @@ describe( 'FontSizePicker', () => {
|
|
|
535
538
|
}
|
|
536
539
|
|
|
537
540
|
function commonTests( fontSizes: FontSize[] ) {
|
|
538
|
-
it( 'shows custom input when value is unknown', () => {
|
|
539
|
-
render(
|
|
541
|
+
it( 'shows custom input when value is unknown', async () => {
|
|
542
|
+
await render(
|
|
543
|
+
<FontSizePicker fontSizes={ fontSizes } value="3px" />
|
|
544
|
+
);
|
|
540
545
|
expect( screen.getByLabelText( 'Custom' ) ).toBeVisible();
|
|
541
546
|
} );
|
|
542
547
|
|
|
543
|
-
it( 'hides custom input when disableCustomFontSizes is set to `true` with a custom font size', () => {
|
|
544
|
-
const { rerender } = render(
|
|
548
|
+
it( 'hides custom input when disableCustomFontSizes is set to `true` with a custom font size', async () => {
|
|
549
|
+
const { rerender } = await render(
|
|
545
550
|
<FontSizePicker fontSizes={ fontSizes } value="3px" />
|
|
546
551
|
);
|
|
547
552
|
expect( screen.getByLabelText( 'Custom' ) ).toBeVisible();
|
|
@@ -558,8 +563,8 @@ describe( 'FontSizePicker', () => {
|
|
|
558
563
|
).not.toBeInTheDocument();
|
|
559
564
|
} );
|
|
560
565
|
|
|
561
|
-
it( "doesn't hide custom input when the selected font size is a predef", () => {
|
|
562
|
-
const { rerender } = render(
|
|
566
|
+
it( "doesn't hide custom input when the selected font size is a predef", async () => {
|
|
567
|
+
const { rerender } = await render(
|
|
563
568
|
<FontSizePicker fontSizes={ fontSizes } value="3px" />
|
|
564
569
|
);
|
|
565
570
|
expect( screen.getByLabelText( 'Custom' ) ).toBeVisible();
|
|
@@ -576,7 +581,7 @@ describe( 'FontSizePicker', () => {
|
|
|
576
581
|
it( 'allows custom values by default', async () => {
|
|
577
582
|
const user = userEvent.setup();
|
|
578
583
|
const onChange = jest.fn();
|
|
579
|
-
render(
|
|
584
|
+
await render(
|
|
580
585
|
<FontSizePicker fontSizes={ fontSizes } onChange={ onChange } />
|
|
581
586
|
);
|
|
582
587
|
await user.click(
|
|
@@ -590,7 +595,9 @@ describe( 'FontSizePicker', () => {
|
|
|
590
595
|
it( 'allows switching between custom and predef inputs when pressing the dedicated toggle', async () => {
|
|
591
596
|
const user = userEvent.setup();
|
|
592
597
|
|
|
593
|
-
render(
|
|
598
|
+
await render(
|
|
599
|
+
<ControlledFontSizePicker fontSizes={ fontSizes } />
|
|
600
|
+
);
|
|
594
601
|
|
|
595
602
|
await user.click(
|
|
596
603
|
screen.getByRole( 'button', { name: 'Set custom size' } )
|
|
@@ -607,8 +614,8 @@ describe( 'FontSizePicker', () => {
|
|
|
607
614
|
).not.toBeInTheDocument();
|
|
608
615
|
} );
|
|
609
616
|
|
|
610
|
-
it( 'does not allow custom values when disableCustomFontSizes is set', () => {
|
|
611
|
-
render(
|
|
617
|
+
it( 'does not allow custom values when disableCustomFontSizes is set', async () => {
|
|
618
|
+
await render(
|
|
612
619
|
<FontSizePicker
|
|
613
620
|
fontSizes={ fontSizes }
|
|
614
621
|
disableCustomFontSizes
|
|
@@ -621,7 +628,7 @@ describe( 'FontSizePicker', () => {
|
|
|
621
628
|
|
|
622
629
|
it( 'does not display a slider by default', async () => {
|
|
623
630
|
const user = userEvent.setup();
|
|
624
|
-
render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
631
|
+
await render( <FontSizePicker fontSizes={ fontSizes } /> );
|
|
625
632
|
await user.click(
|
|
626
633
|
screen.getByRole( 'button', { name: 'Set custom size' } )
|
|
627
634
|
);
|
|
@@ -633,7 +640,7 @@ describe( 'FontSizePicker', () => {
|
|
|
633
640
|
it( 'allows a slider to be used when withSlider is set', async () => {
|
|
634
641
|
const user = userEvent.setup();
|
|
635
642
|
const onChange = jest.fn();
|
|
636
|
-
render(
|
|
643
|
+
await render(
|
|
637
644
|
<FontSizePicker
|
|
638
645
|
fontSizes={ fontSizes }
|
|
639
646
|
withSlider
|
|
@@ -654,7 +661,7 @@ describe( 'FontSizePicker', () => {
|
|
|
654
661
|
it( 'allows reset by default', async () => {
|
|
655
662
|
const user = userEvent.setup();
|
|
656
663
|
const onChange = jest.fn();
|
|
657
|
-
render(
|
|
664
|
+
await render(
|
|
658
665
|
<FontSizePicker
|
|
659
666
|
fontSizes={ fontSizes }
|
|
660
667
|
value={ fontSizes[ 0 ].size }
|
|
@@ -671,7 +678,7 @@ describe( 'FontSizePicker', () => {
|
|
|
671
678
|
|
|
672
679
|
it( 'does not allow reset when withReset is false', async () => {
|
|
673
680
|
const user = userEvent.setup();
|
|
674
|
-
render(
|
|
681
|
+
await render(
|
|
675
682
|
<FontSizePicker
|
|
676
683
|
fontSizes={ fontSizes }
|
|
677
684
|
value={ fontSizes[ 0 ].size }
|
|
@@ -689,7 +696,7 @@ describe( 'FontSizePicker', () => {
|
|
|
689
696
|
it( 'applies custom units to custom font size control', async () => {
|
|
690
697
|
const user = userEvent.setup();
|
|
691
698
|
|
|
692
|
-
render(
|
|
699
|
+
await render(
|
|
693
700
|
<FontSizePicker
|
|
694
701
|
fontSizes={ fontSizes }
|
|
695
702
|
value={ fontSizes[ 0 ].size }
|
|
@@ -17,26 +17,7 @@ import type { WordPressComponentProps } from '../context';
|
|
|
17
17
|
|
|
18
18
|
export const noop = () => {};
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
* FormToggle switches a single setting on or off.
|
|
22
|
-
*
|
|
23
|
-
* ```jsx
|
|
24
|
-
* import { FormToggle } from '@wordpress/components';
|
|
25
|
-
* import { useState } from '@wordpress/element';
|
|
26
|
-
*
|
|
27
|
-
* const MyFormToggle = () => {
|
|
28
|
-
* const [ isChecked, setChecked ] = useState( true );
|
|
29
|
-
*
|
|
30
|
-
* return (
|
|
31
|
-
* <FormToggle
|
|
32
|
-
* checked={ isChecked }
|
|
33
|
-
* onChange={ () => setChecked( ( state ) => ! state ) }
|
|
34
|
-
* />
|
|
35
|
-
* );
|
|
36
|
-
* };
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export function FormToggle(
|
|
20
|
+
function UnforwardedFormToggle(
|
|
40
21
|
props: WordPressComponentProps< FormToggleProps, 'input', false >,
|
|
41
22
|
ref: ForwardedRef< HTMLInputElement >
|
|
42
23
|
) {
|
|
@@ -71,4 +52,25 @@ export function FormToggle(
|
|
|
71
52
|
);
|
|
72
53
|
}
|
|
73
54
|
|
|
74
|
-
|
|
55
|
+
/**
|
|
56
|
+
* FormToggle switches a single setting on or off.
|
|
57
|
+
*
|
|
58
|
+
* ```jsx
|
|
59
|
+
* import { FormToggle } from '@wordpress/components';
|
|
60
|
+
* import { useState } from '@wordpress/element';
|
|
61
|
+
*
|
|
62
|
+
* const MyFormToggle = () => {
|
|
63
|
+
* const [ isChecked, setChecked ] = useState( true );
|
|
64
|
+
*
|
|
65
|
+
* return (
|
|
66
|
+
* <FormToggle
|
|
67
|
+
* checked={ isChecked }
|
|
68
|
+
* onChange={ () => setChecked( ( state ) => ! state ) }
|
|
69
|
+
* />
|
|
70
|
+
* );
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export const FormToggle = forwardRef( UnforwardedFormToggle );
|
|
75
|
+
|
|
76
|
+
export default FormToggle;
|
package/src/guide/index.tsx
CHANGED
|
@@ -144,6 +144,7 @@ function Guide( {
|
|
|
144
144
|
className="components-guide__back-button"
|
|
145
145
|
variant="tertiary"
|
|
146
146
|
onClick={ goBack }
|
|
147
|
+
__next40pxDefaultSize
|
|
147
148
|
>
|
|
148
149
|
{ __( 'Previous' ) }
|
|
149
150
|
</Button>
|
|
@@ -153,6 +154,7 @@ function Guide( {
|
|
|
153
154
|
className="components-guide__forward-button"
|
|
154
155
|
variant="primary"
|
|
155
156
|
onClick={ goForward }
|
|
157
|
+
__next40pxDefaultSize
|
|
156
158
|
>
|
|
157
159
|
{ __( 'Next' ) }
|
|
158
160
|
</Button>
|
package/src/heading/types.ts
CHANGED
|
@@ -17,10 +17,7 @@ export type HeadingSize =
|
|
|
17
17
|
| '5'
|
|
18
18
|
| '6';
|
|
19
19
|
|
|
20
|
-
export type HeadingProps = Omit<
|
|
21
|
-
TextProps,
|
|
22
|
-
'size' | 'isBlock' | 'color' | 'weight'
|
|
23
|
-
> & {
|
|
20
|
+
export type HeadingProps = Omit< TextProps, 'isBlock' | 'color' | 'weight' > & {
|
|
24
21
|
/**
|
|
25
22
|
* Passing any of the heading levels to `level` will both render the correct
|
|
26
23
|
* typographic text size as well as the semantic element corresponding to
|
package/src/modal/index.tsx
CHANGED
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
-
import type {
|
|
6
|
-
ForwardedRef,
|
|
7
|
-
KeyboardEvent,
|
|
8
|
-
MutableRefObject,
|
|
9
|
-
UIEvent,
|
|
10
|
-
} from 'react';
|
|
5
|
+
import type { ForwardedRef, KeyboardEvent, RefObject, UIEvent } from 'react';
|
|
11
6
|
|
|
12
7
|
/**
|
|
13
8
|
* WordPress dependencies
|
|
@@ -44,9 +39,10 @@ import type { ModalProps } from './types';
|
|
|
44
39
|
import { withIgnoreIMEEvents } from '../utils/with-ignore-ime-events';
|
|
45
40
|
|
|
46
41
|
// Used to track and dismiss the prior modal when another opens unless nested.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
type Dismissers = Set<
|
|
43
|
+
RefObject< ModalProps[ 'onRequestClose' ] | undefined >
|
|
44
|
+
>;
|
|
45
|
+
const ModalContext = createContext< Dismissers >( new Set() );
|
|
50
46
|
|
|
51
47
|
// Used to track body class names applied while modals are open.
|
|
52
48
|
const bodyOpenClasses = new Map< string, number >();
|
|
@@ -147,23 +143,28 @@ function UnforwardedModal(
|
|
|
147
143
|
// one should remain open at a time and the list enables closing prior ones.
|
|
148
144
|
const dismissers = useContext( ModalContext );
|
|
149
145
|
// Used for the tracking and dismissing any nested modals.
|
|
150
|
-
const nestedDismissers =
|
|
146
|
+
const [ nestedDismissers ] = useState< Dismissers >( () => new Set() );
|
|
151
147
|
|
|
152
148
|
// Updates the stack tracking open modals at this level and calls
|
|
153
149
|
// onRequestClose for any prior and/or nested modals as applicable.
|
|
154
150
|
useEffect( () => {
|
|
155
|
-
dismissers
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
// add this modal instance to the dismissers set
|
|
152
|
+
dismissers.add( refOnRequestClose );
|
|
153
|
+
// request that all the other modals close themselves
|
|
154
|
+
for ( const dismisser of dismissers ) {
|
|
155
|
+
if ( dismisser !== refOnRequestClose ) {
|
|
156
|
+
dismisser.current?.();
|
|
157
|
+
}
|
|
159
158
|
}
|
|
160
|
-
|
|
161
|
-
const nested = nestedDismissers.current;
|
|
162
159
|
return () => {
|
|
163
|
-
nested
|
|
164
|
-
|
|
160
|
+
// request that all the nested modals close themselves
|
|
161
|
+
for ( const dismisser of nestedDismissers ) {
|
|
162
|
+
dismisser.current?.();
|
|
163
|
+
}
|
|
164
|
+
// remove this modal instance from the dismissers set
|
|
165
|
+
dismissers.delete( refOnRequestClose );
|
|
165
166
|
};
|
|
166
|
-
}, [ dismissers ] );
|
|
167
|
+
}, [ dismissers, nestedDismissers ] );
|
|
167
168
|
|
|
168
169
|
// Adds/removes the value of bodyOpenClassName to body element.
|
|
169
170
|
useEffect( () => {
|
|
@@ -350,7 +351,7 @@ function UnforwardedModal(
|
|
|
350
351
|
);
|
|
351
352
|
|
|
352
353
|
return createPortal(
|
|
353
|
-
<ModalContext.Provider value={ nestedDismissers
|
|
354
|
+
<ModalContext.Provider value={ nestedDismissers }>
|
|
354
355
|
{ modal }
|
|
355
356
|
</ModalContext.Provider>,
|
|
356
357
|
document.body
|