@wordpress/components 21.2.0 → 21.3.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 +35 -3
- package/CONTRIBUTING.md +20 -0
- package/build/border-box-control/border-box-control/component.js +2 -0
- package/build/border-box-control/border-box-control/component.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +4 -1
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-control/border-control/component.js +2 -0
- package/build/border-control/border-control/component.js.map +1 -1
- package/build/disabled/index.js +6 -26
- package/build/disabled/index.js.map +1 -1
- package/build/font-size-picker/index.js +1 -1
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/styles.js +5 -13
- package/build/font-size-picker/styles.js.map +1 -1
- package/build/font-size-picker/utils.js +1 -1
- package/build/font-size-picker/utils.js.map +1 -1
- package/build/form-token-field/suggestions-list.js +5 -5
- package/build/form-token-field/suggestions-list.js.map +1 -1
- package/build/higher-order/with-fallback-styles/index.js +1 -1
- package/build/higher-order/with-fallback-styles/index.js.map +1 -1
- package/build/index.js +8 -6
- package/build/index.js.map +1 -1
- package/build/modal/aria-helper.js +2 -3
- package/build/modal/aria-helper.js.map +1 -1
- package/build/modal/index.js +42 -11
- package/build/modal/index.js.map +1 -1
- package/build/modal/types.js +6 -0
- package/build/modal/types.js.map +1 -0
- package/build/navigator/index.js +8 -8
- package/build/navigator/index.js.map +1 -1
- package/build/navigator/navigator-back-button/component.js +5 -4
- package/build/navigator/navigator-back-button/component.js.map +1 -1
- package/build/navigator/navigator-back-button/index.js +1 -1
- package/build/navigator/navigator-back-button/index.js.map +1 -1
- package/build/navigator/navigator-button/component.js +5 -4
- package/build/navigator/navigator-button/component.js.map +1 -1
- package/build/navigator/navigator-button/index.js +1 -1
- package/build/navigator/navigator-button/index.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +10 -7
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/navigator/navigator-provider/index.js +1 -1
- package/build/navigator/navigator-provider/index.js.map +1 -1
- package/build/navigator/navigator-screen/component.js +24 -27
- package/build/navigator/navigator-screen/component.js.map +1 -1
- package/build/navigator/navigator-screen/index.js +1 -1
- package/build/navigator/navigator-screen/index.js.map +1 -1
- package/build/sandbox/index.js +55 -59
- package/build/sandbox/index.js.map +1 -1
- package/build/sandbox/index.native.js +63 -62
- package/build/sandbox/index.native.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build/tab-panel/index.js +4 -4
- package/build/tab-panel/index.js.map +1 -1
- package/build/theme/index.js +62 -0
- package/build/theme/index.js.map +1 -0
- package/build/theme/styles.js +33 -0
- package/build/theme/styles.js.map +1 -0
- package/build/theme/types.js +6 -0
- package/build/theme/types.js.map +1 -0
- package/build/tools-panel/tools-panel/hook.js +3 -3
- package/build/tools-panel/tools-panel/hook.js.map +1 -1
- package/build/tools-panel/tools-panel-item/hook.js +6 -6
- package/build/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build/tooltip/index.js +4 -1
- package/build/tooltip/index.js.map +1 -1
- package/build/tooltip/index.native.js +17 -4
- package/build/tooltip/index.native.js.map +1 -1
- package/build-module/border-box-control/border-box-control/component.js +2 -0
- package/build-module/border-box-control/border-box-control/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +4 -1
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-control/border-control/component.js +2 -0
- package/build-module/border-control/border-control/component.js.map +1 -1
- package/build-module/disabled/index.js +7 -26
- package/build-module/disabled/index.js.map +1 -1
- package/build-module/font-size-picker/index.js +1 -1
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/styles.js +5 -13
- package/build-module/font-size-picker/styles.js.map +1 -1
- package/build-module/font-size-picker/utils.js +1 -1
- package/build-module/font-size-picker/utils.js.map +1 -1
- package/build-module/form-token-field/suggestions-list.js +5 -5
- package/build-module/form-token-field/suggestions-list.js.map +1 -1
- package/build-module/higher-order/with-fallback-styles/index.js +2 -2
- package/build-module/higher-order/with-fallback-styles/index.js.map +1 -1
- package/build-module/index.js +2 -1
- package/build-module/index.js.map +1 -1
- package/build-module/modal/aria-helper.js +2 -3
- package/build-module/modal/aria-helper.js.map +1 -1
- package/build-module/modal/index.js +44 -12
- package/build-module/modal/index.js.map +1 -1
- package/build-module/modal/types.js +2 -0
- package/build-module/modal/types.js.map +1 -0
- package/build-module/navigator/index.js +4 -4
- package/build-module/navigator/index.js.map +1 -1
- package/build-module/navigator/navigator-back-button/component.js +3 -3
- package/build-module/navigator/navigator-back-button/component.js.map +1 -1
- package/build-module/navigator/navigator-back-button/index.js +1 -1
- package/build-module/navigator/navigator-back-button/index.js.map +1 -1
- package/build-module/navigator/navigator-button/component.js +3 -3
- package/build-module/navigator/navigator-button/component.js.map +1 -1
- package/build-module/navigator/navigator-button/index.js +1 -1
- package/build-module/navigator/navigator-button/index.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +8 -6
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/navigator/navigator-provider/index.js +1 -1
- package/build-module/navigator/navigator-provider/index.js.map +1 -1
- package/build-module/navigator/navigator-screen/component.js +12 -26
- package/build-module/navigator/navigator-screen/component.js.map +1 -1
- package/build-module/navigator/navigator-screen/index.js +1 -1
- package/build-module/navigator/navigator-screen/index.js.map +1 -1
- package/build-module/sandbox/index.js +56 -59
- package/build-module/sandbox/index.js.map +1 -1
- package/build-module/sandbox/index.native.js +54 -52
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build-module/tab-panel/index.js +4 -4
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/theme/index.js +52 -0
- package/build-module/theme/index.js.map +1 -0
- package/build-module/theme/styles.js +25 -0
- package/build-module/theme/styles.js.map +1 -0
- package/build-module/theme/types.js +2 -0
- package/build-module/theme/types.js.map +1 -0
- package/build-module/tools-panel/tools-panel/hook.js +3 -3
- package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-module/tools-panel/tools-panel-item/hook.js +6 -6
- package/build-module/tools-panel/tools-panel-item/hook.js.map +1 -1
- package/build-module/tooltip/index.js +4 -1
- package/build-module/tooltip/index.js.map +1 -1
- package/build-module/tooltip/index.native.js +17 -4
- package/build-module/tooltip/index.native.js.map +1 -1
- package/build-style/style-rtl.css +26 -22
- package/build-style/style.css +26 -22
- package/build-types/border-box-control/border-box-control/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control/hook.d.ts +1 -0
- package/build-types/border-box-control/border-box-control/hook.d.ts.map +1 -1
- package/build-types/border-control/border-control/component.d.ts +1 -0
- package/build-types/border-control/border-control/component.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts +1 -0
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/border-control/stories/index.d.ts +6 -0
- package/build-types/border-control/stories/index.d.ts.map +1 -1
- package/build-types/border-control/types.d.ts +4 -0
- package/build-types/border-control/types.d.ts.map +1 -1
- package/build-types/confirm-dialog/types.d.ts +5 -1
- package/build-types/confirm-dialog/types.d.ts.map +1 -1
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts.map +1 -1
- package/build-types/modal/aria-helper.d.ts +4 -4
- package/build-types/modal/aria-helper.d.ts.map +1 -1
- package/build-types/modal/index.d.ts +35 -2
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/modal/stories/index.d.ts +9 -0
- package/build-types/modal/stories/index.d.ts.map +1 -0
- package/build-types/modal/test/aria-helper.d.ts +2 -0
- package/build-types/modal/test/aria-helper.d.ts.map +1 -0
- package/build-types/modal/test/index.d.ts +2 -0
- package/build-types/modal/test/index.d.ts.map +1 -0
- package/build-types/modal/types.d.ts +134 -0
- package/build-types/modal/types.d.ts.map +1 -0
- package/build-types/navigator/index.d.ts +4 -4
- package/build-types/navigator/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/component.d.ts +4 -2
- package/build-types/navigator/navigator-back-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +1 -0
- package/build-types/navigator/navigator-back-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/index.d.ts +1 -1
- package/build-types/navigator/navigator-back-button/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/component.d.ts +4 -2
- package/build-types/navigator/navigator-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +1 -0
- package/build-types/navigator/navigator-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/index.d.ts +1 -1
- package/build-types/navigator/navigator-button/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts +2 -2
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/index.d.ts +1 -1
- package/build-types/navigator/navigator-provider/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/component.d.ts +2 -2
- package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-screen/index.d.ts +1 -1
- package/build-types/navigator/navigator-screen/index.d.ts.map +1 -1
- package/build-types/navigator/stories/index.d.ts +9 -0
- package/build-types/navigator/stories/index.d.ts.map +1 -0
- package/build-types/navigator/test/index.d.ts +2 -0
- package/build-types/navigator/test/index.d.ts.map +1 -0
- package/build-types/navigator/types.d.ts +4 -1
- package/build-types/navigator/types.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/theme/index.d.ts +31 -0
- package/build-types/theme/index.d.ts.map +1 -0
- package/build-types/theme/stories/index.d.ts +13 -0
- package/build-types/theme/stories/index.d.ts.map +1 -0
- package/build-types/theme/styles.d.ts +10 -0
- package/build-types/theme/styles.d.ts.map +1 -0
- package/build-types/theme/test/index.d.ts +2 -0
- package/build-types/theme/test/index.d.ts.map +1 -0
- package/build-types/theme/types.d.ts +21 -0
- package/build-types/theme/types.d.ts.map +1 -0
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel-item/hook.d.ts.map +1 -1
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/base-field/test/index.js +4 -6
- package/src/border-box-control/border-box-control/component.tsx +2 -0
- package/src/border-box-control/border-box-control/hook.ts +4 -0
- package/src/border-box-control/test/index.js +7 -2
- package/src/border-control/border-control/README.md +6 -0
- package/src/border-control/border-control/component.tsx +2 -0
- package/src/border-control/types.ts +4 -0
- package/src/button/style.scss +25 -25
- package/src/button/test/index.js +3 -5
- package/src/combobox-control/test/index.js +1 -1
- package/src/confirm-dialog/types.ts +6 -0
- package/src/date-time/time/test/index.tsx +2 -6
- package/src/disabled/index.tsx +11 -33
- package/src/disabled/test/index.tsx +14 -82
- package/src/dropdown/test/index.js +4 -3
- package/src/font-size-picker/index.tsx +1 -1
- package/src/font-size-picker/styles.ts +3 -1
- package/src/font-size-picker/test/index.tsx +2 -2
- package/src/font-size-picker/test/utils.ts +5 -5
- package/src/font-size-picker/utils.ts +1 -1
- package/src/form-file-upload/test/index.tsx +1 -1
- package/src/form-token-field/suggestions-list.tsx +5 -5
- package/src/higher-order/with-fallback-styles/index.js +6 -2
- package/src/higher-order/with-focus-outside/test/index.js +44 -45
- package/src/higher-order/with-focus-return/test/index.js +34 -30
- package/src/higher-order/with-notices/test/index.js +1 -1
- package/src/index.js +2 -1
- package/src/input-control/test/index.js +2 -2
- package/src/item-group/test/index.js +2 -2
- package/src/menu-item/test/index.js +0 -3
- package/src/mobile/bottom-sheet/test/range-cell.native.js +16 -14
- package/src/modal/README.md +53 -54
- package/src/modal/{aria-helper.js → aria-helper.ts} +5 -7
- package/src/modal/{index.js → index.tsx} +48 -12
- package/src/modal/stories/{index.js → index.tsx} +47 -42
- package/src/modal/test/{aria-helper.js → aria-helper.ts} +0 -0
- package/src/modal/test/{index.js → index.tsx} +13 -3
- package/src/modal/types.ts +144 -0
- package/src/navigation/test/index.js +1 -1
- package/src/navigator/index.ts +4 -4
- package/src/navigator/navigator-back-button/component.tsx +4 -4
- package/src/navigator/navigator-back-button/index.ts +1 -1
- package/src/navigator/navigator-button/component.tsx +4 -4
- package/src/navigator/navigator-button/index.ts +1 -1
- package/src/navigator/navigator-provider/component.tsx +6 -4
- package/src/navigator/navigator-provider/index.ts +1 -1
- package/src/navigator/navigator-screen/component.tsx +20 -26
- package/src/navigator/navigator-screen/index.ts +1 -1
- package/src/navigator/stories/index.tsx +210 -0
- package/src/navigator/test/index.tsx +509 -0
- package/src/navigator/types.ts +2 -0
- package/src/notice/test/__snapshots__/index.js.snap +39 -38
- package/src/notice/test/index.js +15 -36
- package/src/notice/test/list.js +6 -14
- package/src/number-control/test/index.js +3 -2
- package/src/panel/test/body.js +2 -2
- package/src/placeholder/style.scss +5 -0
- package/src/sandbox/index.js +62 -47
- package/src/sandbox/index.native.js +72 -52
- package/src/sandbox/test/index.js +7 -10
- package/src/shortcut/test/index.tsx +1 -1
- package/src/slot-fill/bubbles-virtually/slot-fill-provider.js +5 -3
- package/src/style.scss +4 -0
- package/src/tab-panel/index.tsx +4 -7
- package/src/text-highlight/test/index.tsx +1 -3
- package/src/theme/README.md +34 -0
- package/src/theme/index.tsx +51 -0
- package/src/theme/stories/index.tsx +47 -0
- package/src/theme/styles.ts +28 -0
- package/src/theme/test/index.tsx +101 -0
- package/src/theme/types.ts +21 -0
- package/src/toolbar/test/index.js +2 -2
- package/src/toolbar-group/test/index.js +6 -10
- package/src/tools-panel/test/index.js +4 -6
- package/src/tools-panel/tools-panel/hook.ts +2 -9
- package/src/tools-panel/tools-panel-item/hook.ts +17 -3
- package/src/tooltip/index.js +3 -0
- package/src/tooltip/index.native.js +15 -0
- package/src/tooltip/test/index.native.js +1 -2
- package/src/tree-grid/test/__snapshots__/cell.js.snap +1 -3
- package/src/tree-grid/test/__snapshots__/roving-tab-index-item.js.snap +17 -15
- package/src/tree-grid/test/__snapshots__/row.js.snap +25 -21
- package/src/tree-grid/test/cell.js +4 -4
- package/src/tree-grid/test/roving-tab-index-item.js +8 -8
- package/src/tree-grid/test/roving-tab-index.js +3 -3
- package/src/tree-grid/test/row.js +20 -16
- package/src/truncate/test/index.tsx +4 -4
- package/src/ui/shortcut/test/index.js +2 -1
- package/src/ui/spinner/test/index.js +14 -13
- package/src/ui/tooltip/test/index.js +16 -14
- package/src/utils/theme-variables.scss +8 -0
- package/src/visually-hidden/README.md +4 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/navigator/stories/index.js +0 -194
- package/src/navigator/test/index.js +0 -472
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
const LIVE_REGION_ARIA_ROLES = new Set( [
|
|
4
2
|
'alert',
|
|
5
3
|
'status',
|
|
@@ -8,7 +6,7 @@ const LIVE_REGION_ARIA_ROLES = new Set( [
|
|
|
8
6
|
'timer',
|
|
9
7
|
] );
|
|
10
8
|
|
|
11
|
-
let hiddenElements = [],
|
|
9
|
+
let hiddenElements: Element[] = [],
|
|
12
10
|
isHidden = false;
|
|
13
11
|
|
|
14
12
|
/**
|
|
@@ -21,9 +19,9 @@ let hiddenElements = [],
|
|
|
21
19
|
* we should consider removing these helper functions in favor of
|
|
22
20
|
* `aria-modal="true"`.
|
|
23
21
|
*
|
|
24
|
-
* @param {
|
|
22
|
+
* @param {HTMLDivElement} unhiddenElement The element that should not be hidden.
|
|
25
23
|
*/
|
|
26
|
-
export function hideApp( unhiddenElement ) {
|
|
24
|
+
export function hideApp( unhiddenElement?: HTMLDivElement ) {
|
|
27
25
|
if ( isHidden ) {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
@@ -47,13 +45,13 @@ export function hideApp( unhiddenElement ) {
|
|
|
47
45
|
*
|
|
48
46
|
* @return {boolean} Whether the element should not be hidden from screen-readers.
|
|
49
47
|
*/
|
|
50
|
-
export function elementShouldBeHidden( element ) {
|
|
48
|
+
export function elementShouldBeHidden( element: Element ) {
|
|
51
49
|
const role = element.getAttribute( 'role' );
|
|
52
50
|
return ! (
|
|
53
51
|
element.tagName === 'SCRIPT' ||
|
|
54
52
|
element.hasAttribute( 'aria-hidden' ) ||
|
|
55
53
|
element.hasAttribute( 'aria-live' ) ||
|
|
56
|
-
LIVE_REGION_ARIA_ROLES.has( role )
|
|
54
|
+
( role && LIVE_REGION_ARIA_ROLES.has( role ) )
|
|
57
55
|
);
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* External dependencies
|
|
5
3
|
*/
|
|
6
4
|
import classnames from 'classnames';
|
|
5
|
+
import type { ForwardedRef, KeyboardEvent, UIEvent } from 'react';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* WordPress dependencies
|
|
@@ -33,11 +32,15 @@ import { close } from '@wordpress/icons';
|
|
|
33
32
|
import * as ariaHelper from './aria-helper';
|
|
34
33
|
import Button from '../button';
|
|
35
34
|
import StyleProvider from '../style-provider';
|
|
35
|
+
import type { ModalProps } from './types';
|
|
36
36
|
|
|
37
37
|
// Used to count the number of open modals.
|
|
38
38
|
let openModalCount = 0;
|
|
39
39
|
|
|
40
|
-
function
|
|
40
|
+
function UnforwardedModal(
|
|
41
|
+
props: ModalProps,
|
|
42
|
+
forwardedRef: ForwardedRef< HTMLDivElement >
|
|
43
|
+
) {
|
|
41
44
|
const {
|
|
42
45
|
bodyOpenClassName = 'modal-open',
|
|
43
46
|
role = 'dialog',
|
|
@@ -48,8 +51,8 @@ function Modal( props, forwardedRef ) {
|
|
|
48
51
|
isDismissible = true,
|
|
49
52
|
/* Accessibility. */
|
|
50
53
|
aria = {
|
|
51
|
-
labelledby:
|
|
52
|
-
describedby:
|
|
54
|
+
labelledby: undefined,
|
|
55
|
+
describedby: undefined,
|
|
53
56
|
},
|
|
54
57
|
onRequestClose,
|
|
55
58
|
icon,
|
|
@@ -64,7 +67,7 @@ function Modal( props, forwardedRef ) {
|
|
|
64
67
|
__experimentalHideHeader = false,
|
|
65
68
|
} = props;
|
|
66
69
|
|
|
67
|
-
const ref = useRef();
|
|
70
|
+
const ref = useRef< HTMLDivElement >();
|
|
68
71
|
const instanceId = useInstanceId( Modal );
|
|
69
72
|
const headingId = title
|
|
70
73
|
? `components-modal-header-${ instanceId }`
|
|
@@ -94,7 +97,7 @@ function Modal( props, forwardedRef ) {
|
|
|
94
97
|
};
|
|
95
98
|
}, [ bodyOpenClassName ] );
|
|
96
99
|
|
|
97
|
-
function handleEscapeKeyDown( event ) {
|
|
100
|
+
function handleEscapeKeyDown( event: KeyboardEvent< HTMLDivElement > ) {
|
|
98
101
|
if (
|
|
99
102
|
shouldCloseOnEsc &&
|
|
100
103
|
event.code === 'Escape' &&
|
|
@@ -108,8 +111,8 @@ function Modal( props, forwardedRef ) {
|
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
const onContentContainerScroll = useCallback(
|
|
111
|
-
( e ) => {
|
|
112
|
-
const scrollY = e?.
|
|
114
|
+
( e: UIEvent< HTMLDivElement > ) => {
|
|
115
|
+
const scrollY = e?.currentTarget?.scrollTop ?? -1;
|
|
113
116
|
|
|
114
117
|
if ( ! hasScrolledContent && scrollY > 0 ) {
|
|
115
118
|
setHasScrolledContent( true );
|
|
@@ -147,9 +150,9 @@ function Modal( props, forwardedRef ) {
|
|
|
147
150
|
] ) }
|
|
148
151
|
role={ role }
|
|
149
152
|
aria-label={ contentLabel }
|
|
150
|
-
aria-labelledby={ contentLabel ?
|
|
153
|
+
aria-labelledby={ contentLabel ? undefined : headingId }
|
|
151
154
|
aria-describedby={ aria.describedby }
|
|
152
|
-
tabIndex=
|
|
155
|
+
tabIndex={ -1 }
|
|
153
156
|
{ ...( shouldCloseOnClickOutside
|
|
154
157
|
? focusOutsideProps
|
|
155
158
|
: {} ) }
|
|
@@ -204,4 +207,37 @@ function Modal( props, forwardedRef ) {
|
|
|
204
207
|
);
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Modals give users information and choices related to a task they’re trying to
|
|
212
|
+
* accomplish. They can contain critical information, require decisions, or
|
|
213
|
+
* involve multiple tasks.
|
|
214
|
+
*
|
|
215
|
+
* ```jsx
|
|
216
|
+
* import { Button, Modal } from '@wordpress/components';
|
|
217
|
+
* import { useState } from '@wordpress/element';
|
|
218
|
+
*
|
|
219
|
+
* const MyModal = () => {
|
|
220
|
+
* const [ isOpen, setOpen ] = useState( false );
|
|
221
|
+
* const openModal = () => setOpen( true );
|
|
222
|
+
* const closeModal = () => setOpen( false );
|
|
223
|
+
*
|
|
224
|
+
* return (
|
|
225
|
+
* <>
|
|
226
|
+
* <Button variant="secondary" onClick={ openModal }>
|
|
227
|
+
* Open Modal
|
|
228
|
+
* </Button>
|
|
229
|
+
* { isOpen && (
|
|
230
|
+
* <Modal title="This is my modal" onRequestClose={ closeModal }>
|
|
231
|
+
* <Button variant="secondary" onClick={ closeModal }>
|
|
232
|
+
* My custom close button
|
|
233
|
+
* </Button>
|
|
234
|
+
* </Modal>
|
|
235
|
+
* ) }
|
|
236
|
+
* </>
|
|
237
|
+
* );
|
|
238
|
+
* };
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export const Modal = forwardRef( UnforwardedModal );
|
|
242
|
+
|
|
243
|
+
export default Modal;
|
|
@@ -1,33 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import type { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import
|
|
10
|
-
import Icon from '../../icon';
|
|
11
|
-
import Modal from '../';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Internal dependencies
|
|
15
13
|
*/
|
|
16
|
-
import
|
|
17
|
-
import
|
|
14
|
+
import Button from '../../button';
|
|
15
|
+
import Modal from '../';
|
|
16
|
+
import type { ModalProps } from '../types';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
title: 'Components/Modal',
|
|
18
|
+
const meta: ComponentMeta< typeof Modal > = {
|
|
21
19
|
component: Modal,
|
|
20
|
+
title: 'Components/Modal',
|
|
21
|
+
argTypes: {
|
|
22
|
+
children: {
|
|
23
|
+
control: { type: null },
|
|
24
|
+
},
|
|
25
|
+
onKeyDown: {
|
|
26
|
+
control: { type: null },
|
|
27
|
+
},
|
|
28
|
+
focusOnMount: {
|
|
29
|
+
control: { type: 'boolean' },
|
|
30
|
+
},
|
|
31
|
+
role: {
|
|
32
|
+
control: { type: 'text' },
|
|
33
|
+
},
|
|
34
|
+
onRequestClose: {
|
|
35
|
+
action: 'onRequestClose',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
22
38
|
parameters: {
|
|
23
|
-
|
|
39
|
+
controls: { expanded: true },
|
|
24
40
|
},
|
|
25
41
|
};
|
|
42
|
+
export default meta;
|
|
26
43
|
|
|
27
|
-
const
|
|
44
|
+
const Template: ComponentStory< typeof Modal > = ( {
|
|
45
|
+
onRequestClose,
|
|
46
|
+
...args
|
|
47
|
+
} ) => {
|
|
28
48
|
const [ isOpen, setOpen ] = useState( false );
|
|
29
49
|
const openModal = () => setOpen( true );
|
|
30
|
-
const closeModal = () =>
|
|
50
|
+
const closeModal: ModalProps[ 'onRequestClose' ] = ( event ) => {
|
|
51
|
+
setOpen( false );
|
|
52
|
+
onRequestClose( event );
|
|
53
|
+
};
|
|
31
54
|
|
|
32
55
|
return (
|
|
33
56
|
<>
|
|
@@ -36,9 +59,9 @@ const ModalExample = ( props ) => {
|
|
|
36
59
|
</Button>
|
|
37
60
|
{ isOpen && (
|
|
38
61
|
<Modal
|
|
39
|
-
{ ...props }
|
|
40
62
|
onRequestClose={ closeModal }
|
|
41
63
|
style={ { maxWidth: '600px' } }
|
|
64
|
+
{ ...args }
|
|
42
65
|
>
|
|
43
66
|
<p>
|
|
44
67
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
|
|
@@ -61,32 +84,14 @@ const ModalExample = ( props ) => {
|
|
|
61
84
|
);
|
|
62
85
|
};
|
|
63
86
|
|
|
64
|
-
export const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const __experimentalHideHeader = boolean(
|
|
75
|
-
'__experimentalHideHeader',
|
|
76
|
-
false
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const iconComponent = showIcon ? <Icon icon={ wordpress } /> : null;
|
|
80
|
-
|
|
81
|
-
const modalProps = {
|
|
82
|
-
icon: iconComponent,
|
|
83
|
-
focusOnMount,
|
|
84
|
-
isDismissible,
|
|
85
|
-
shouldCloseOnEsc,
|
|
86
|
-
shouldCloseOnClickOutside,
|
|
87
|
-
title,
|
|
88
|
-
__experimentalHideHeader,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return <ModalExample { ...modalProps } />;
|
|
87
|
+
export const Default: ComponentStory< typeof Modal > = Template.bind( {} );
|
|
88
|
+
Default.args = {
|
|
89
|
+
title: 'Title',
|
|
90
|
+
};
|
|
91
|
+
Default.parameters = {
|
|
92
|
+
docs: {
|
|
93
|
+
source: {
|
|
94
|
+
code: '',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
92
97
|
};
|
|
File without changes
|
|
@@ -8,10 +8,15 @@ import { render, screen, within } from '@testing-library/react';
|
|
|
8
8
|
*/
|
|
9
9
|
import Modal from '../';
|
|
10
10
|
|
|
11
|
+
const noop = () => {};
|
|
12
|
+
|
|
11
13
|
describe( 'Modal', () => {
|
|
12
14
|
it( 'applies the aria-describedby attribute when provided', () => {
|
|
13
15
|
render(
|
|
14
|
-
<Modal
|
|
16
|
+
<Modal
|
|
17
|
+
aria={ { describedby: 'description-id' } }
|
|
18
|
+
onRequestClose={ noop }
|
|
19
|
+
>
|
|
15
20
|
{ /* eslint-disable-next-line no-restricted-syntax */ }
|
|
16
21
|
<p id="description-id">Description</p>
|
|
17
22
|
</Modal>
|
|
@@ -24,7 +29,7 @@ describe( 'Modal', () => {
|
|
|
24
29
|
|
|
25
30
|
it( 'applies the aria-labelledby attribute when provided', () => {
|
|
26
31
|
render(
|
|
27
|
-
<Modal aria={ { labelledby: 'title-id' } }>
|
|
32
|
+
<Modal aria={ { labelledby: 'title-id' } } onRequestClose={ noop }>
|
|
28
33
|
{ /* eslint-disable-next-line no-restricted-syntax */ }
|
|
29
34
|
<h1 id="title-id">Modal Title Text</h1>
|
|
30
35
|
</Modal>
|
|
@@ -39,6 +44,7 @@ describe( 'Modal', () => {
|
|
|
39
44
|
<Modal
|
|
40
45
|
title="Modal Title Attribute"
|
|
41
46
|
aria={ { labelledby: 'title-id' } }
|
|
47
|
+
onRequestClose={ noop }
|
|
42
48
|
>
|
|
43
49
|
{ /* eslint-disable-next-line no-restricted-syntax */ }
|
|
44
50
|
<h1 id="title-id">Modal Title Text</h1>
|
|
@@ -51,7 +57,11 @@ describe( 'Modal', () => {
|
|
|
51
57
|
|
|
52
58
|
it( 'hides the header when the `__experimentalHideHeader` prop is used', () => {
|
|
53
59
|
render(
|
|
54
|
-
<Modal
|
|
60
|
+
<Modal
|
|
61
|
+
title="Test Title"
|
|
62
|
+
__experimentalHideHeader
|
|
63
|
+
onRequestClose={ noop }
|
|
64
|
+
>
|
|
55
65
|
<p>Modal content</p>
|
|
56
66
|
</Modal>
|
|
57
67
|
);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type {
|
|
5
|
+
AriaRole,
|
|
6
|
+
CSSProperties,
|
|
7
|
+
ReactNode,
|
|
8
|
+
KeyboardEventHandler,
|
|
9
|
+
KeyboardEvent,
|
|
10
|
+
SyntheticEvent,
|
|
11
|
+
} from 'react';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* WordPress dependencies
|
|
15
|
+
*/
|
|
16
|
+
import type { useFocusOnMount } from '@wordpress/compose';
|
|
17
|
+
|
|
18
|
+
export type ModalProps = {
|
|
19
|
+
aria?: {
|
|
20
|
+
/**
|
|
21
|
+
* If this property is added, it will be added to the modal content
|
|
22
|
+
* `div` as `aria-describedby`.
|
|
23
|
+
*/
|
|
24
|
+
describedby?: string;
|
|
25
|
+
/**
|
|
26
|
+
* If this property is added, it will be added to the modal content
|
|
27
|
+
* `div` as `aria-labelledby`. Use this when you are rendering the title
|
|
28
|
+
* yourself within the modal's content area instead of using the `title`
|
|
29
|
+
* prop. This ensures the title is usable by assistive technology.
|
|
30
|
+
*
|
|
31
|
+
* Titles are required for accessibility reasons, see `contentLabel` and
|
|
32
|
+
* `title` for other ways to provide a title.
|
|
33
|
+
*/
|
|
34
|
+
labelledby?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Class name added to the body element when the modal is open.
|
|
38
|
+
*
|
|
39
|
+
* @default 'modal-open'
|
|
40
|
+
*/
|
|
41
|
+
bodyOpenClassName?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The children elements.
|
|
44
|
+
*/
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
/**
|
|
47
|
+
* If this property is added, it will an additional class name to the modal
|
|
48
|
+
* content `div`.
|
|
49
|
+
*/
|
|
50
|
+
className?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Label on the close button.
|
|
53
|
+
*/
|
|
54
|
+
closeButtonLabel?: string;
|
|
55
|
+
/**
|
|
56
|
+
* If this property is added, it will be added to the modal content `div` as
|
|
57
|
+
* `aria-label`.
|
|
58
|
+
*
|
|
59
|
+
* Titles are required for accessibility reasons, see `aria.labelledby` and
|
|
60
|
+
* `title` for other ways to provide a title.
|
|
61
|
+
*/
|
|
62
|
+
contentLabel?: string;
|
|
63
|
+
/**
|
|
64
|
+
* If this property is true, it will focus the first tabbable element
|
|
65
|
+
* rendered in the modal.
|
|
66
|
+
*
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
focusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];
|
|
70
|
+
/**
|
|
71
|
+
* If this property is added, an icon will be added before the title.
|
|
72
|
+
*/
|
|
73
|
+
icon?: JSX.Element;
|
|
74
|
+
/**
|
|
75
|
+
* If this property is set to false, the modal will not display a close icon
|
|
76
|
+
* and cannot be dismissed.
|
|
77
|
+
*
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
isDismissible?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* This property when set to `true` will render a full screen modal.
|
|
83
|
+
*
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
isFullScreen?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Handle the key down on the modal frame `div`.
|
|
89
|
+
*/
|
|
90
|
+
onKeyDown?: KeyboardEventHandler< HTMLDivElement >;
|
|
91
|
+
/**
|
|
92
|
+
* This function is called to indicate that the modal should be closed.
|
|
93
|
+
*/
|
|
94
|
+
onRequestClose: (
|
|
95
|
+
event?: KeyboardEvent< HTMLDivElement > | SyntheticEvent
|
|
96
|
+
) => void;
|
|
97
|
+
/**
|
|
98
|
+
* If this property is added, it will an additional class name to the modal
|
|
99
|
+
* overlay `div`.
|
|
100
|
+
*/
|
|
101
|
+
overlayClassName?: string;
|
|
102
|
+
/**
|
|
103
|
+
* If this property is added, it will override the default role of the
|
|
104
|
+
* modal.
|
|
105
|
+
*
|
|
106
|
+
* @default 'dialog'
|
|
107
|
+
*/
|
|
108
|
+
role?: AriaRole;
|
|
109
|
+
/**
|
|
110
|
+
* If this property is added, it will determine whether the modal requests
|
|
111
|
+
* to close when a mouse click occurs outside of the modal content.
|
|
112
|
+
*
|
|
113
|
+
* @default true
|
|
114
|
+
*/
|
|
115
|
+
shouldCloseOnClickOutside?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* If this property is added, it will determine whether the modal requests
|
|
118
|
+
* to close when the escape key is pressed.
|
|
119
|
+
*
|
|
120
|
+
* @default true
|
|
121
|
+
*/
|
|
122
|
+
shouldCloseOnEsc?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* If this property is added, it will be added to the modal frame `div`.
|
|
125
|
+
*/
|
|
126
|
+
style?: CSSProperties;
|
|
127
|
+
/**
|
|
128
|
+
* This property is used as the modal header's title.
|
|
129
|
+
*
|
|
130
|
+
* Titles are required for accessibility reasons, see `aria.labelledby` and
|
|
131
|
+
* `contentLabel` for other ways to provide a title.
|
|
132
|
+
*/
|
|
133
|
+
title?: string;
|
|
134
|
+
/**
|
|
135
|
+
* When set to `true`, the Modal's header (including the icon, title and
|
|
136
|
+
* close button) will not be rendered.
|
|
137
|
+
*
|
|
138
|
+
* _Warning_: This property is still experimental. “Experimental” means this
|
|
139
|
+
* is an early implementation subject to drastic and breaking changes.
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
__experimentalHideHeader?: boolean;
|
|
144
|
+
};
|
|
@@ -220,7 +220,7 @@ describe( 'Navigation', () => {
|
|
|
220
220
|
render( <TestNavigation showBadge /> );
|
|
221
221
|
|
|
222
222
|
const menuItem = screen.getAllByRole( 'listitem' );
|
|
223
|
-
expect( menuItem[ 0 ]
|
|
223
|
+
expect( menuItem[ 0 ] ).toHaveTextContent( 'Item 1' + '21' );
|
|
224
224
|
} );
|
|
225
225
|
|
|
226
226
|
it( 'should render menu titles when items exist', () => {
|
package/src/navigator/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { NavigatorProvider } from './navigator-provider';
|
|
2
|
+
export { NavigatorScreen } from './navigator-screen';
|
|
3
|
+
export { NavigatorButton } from './navigator-button';
|
|
4
|
+
export { NavigatorBackButton } from './navigator-back-button';
|
|
5
5
|
export { default as useNavigator } from './use-navigator';
|
|
@@ -11,7 +11,7 @@ import { View } from '../../view';
|
|
|
11
11
|
import { useNavigatorBackButton } from './hook';
|
|
12
12
|
import type { NavigatorBackButtonProps } from '../types';
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function UnconnectedNavigatorBackButton(
|
|
15
15
|
props: WordPressComponentProps< NavigatorBackButtonProps, 'button' >,
|
|
16
16
|
forwardedRef: ForwardedRef< any >
|
|
17
17
|
) {
|
|
@@ -54,9 +54,9 @@ function NavigatorBackButton(
|
|
|
54
54
|
* );
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
export const NavigatorBackButton = contextConnect(
|
|
58
|
+
UnconnectedNavigatorBackButton,
|
|
59
59
|
'NavigatorBackButton'
|
|
60
60
|
);
|
|
61
61
|
|
|
62
|
-
export default
|
|
62
|
+
export default NavigatorBackButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './component';
|
|
1
|
+
export { default as NavigatorBackButton } from './component';
|
|
@@ -11,7 +11,7 @@ import { View } from '../../view';
|
|
|
11
11
|
import { useNavigatorButton } from './hook';
|
|
12
12
|
import type { NavigatorButtonProps } from '../types';
|
|
13
13
|
|
|
14
|
-
function
|
|
14
|
+
function UnconnectedNavigatorButton(
|
|
15
15
|
props: WordPressComponentProps< NavigatorButtonProps, 'button' >,
|
|
16
16
|
forwardedRef: ForwardedRef< any >
|
|
17
17
|
) {
|
|
@@ -53,9 +53,9 @@ function NavigatorButton(
|
|
|
53
53
|
* );
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
const
|
|
57
|
-
|
|
56
|
+
export const NavigatorButton = contextConnect(
|
|
57
|
+
UnconnectedNavigatorButton,
|
|
58
58
|
'NavigatorButton'
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
-
export default
|
|
61
|
+
export default NavigatorButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './component';
|
|
1
|
+
export { default as NavigatorButton } from './component';
|
|
@@ -26,7 +26,7 @@ import type {
|
|
|
26
26
|
NavigatorContext as NavigatorContextType,
|
|
27
27
|
} from '../types';
|
|
28
28
|
|
|
29
|
-
function
|
|
29
|
+
function UnconnectedNavigatorProvider(
|
|
30
30
|
props: WordPressComponentProps< NavigatorProviderProps, 'div' >,
|
|
31
31
|
forwardedRef: ForwardedRef< any >
|
|
32
32
|
) {
|
|
@@ -49,6 +49,7 @@ function NavigatorProvider(
|
|
|
49
49
|
...options,
|
|
50
50
|
path,
|
|
51
51
|
isBack: false,
|
|
52
|
+
hasRestoredFocus: false,
|
|
52
53
|
},
|
|
53
54
|
] );
|
|
54
55
|
},
|
|
@@ -62,6 +63,7 @@ function NavigatorProvider(
|
|
|
62
63
|
{
|
|
63
64
|
...locationHistory[ locationHistory.length - 2 ],
|
|
64
65
|
isBack: true,
|
|
66
|
+
hasRestoredFocus: false,
|
|
65
67
|
},
|
|
66
68
|
] );
|
|
67
69
|
}
|
|
@@ -129,9 +131,9 @@ function NavigatorProvider(
|
|
|
129
131
|
* );
|
|
130
132
|
* ```
|
|
131
133
|
*/
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
+
export const NavigatorProvider = contextConnect(
|
|
135
|
+
UnconnectedNavigatorProvider,
|
|
134
136
|
'NavigatorProvider'
|
|
135
137
|
);
|
|
136
138
|
|
|
137
|
-
export default
|
|
139
|
+
export default NavigatorProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './component';
|
|
1
|
+
export { default as NavigatorProvider } from './component';
|