@wordpress/components 28.8.3 → 28.8.5

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/composite/group-label.js +7 -1
  3. package/build/composite/group-label.js.map +1 -1
  4. package/build/composite/group.js +7 -1
  5. package/build/composite/group.js.map +1 -1
  6. package/build/composite/hover.js +8 -2
  7. package/build/composite/hover.js.map +1 -1
  8. package/build/composite/index.js +5 -1
  9. package/build/composite/index.js.map +1 -1
  10. package/build/composite/item.js +16 -1
  11. package/build/composite/item.js.map +1 -1
  12. package/build/composite/row.js +7 -1
  13. package/build/composite/row.js.map +1 -1
  14. package/build/composite/typeahead.js +8 -2
  15. package/build/composite/typeahead.js.map +1 -1
  16. package/build/date-time/date/index.js +4 -2
  17. package/build/date-time/date/index.js.map +1 -1
  18. package/build/toggle-group-control/toggle-group-control/as-radio-group.js +3 -1
  19. package/build/toggle-group-control/toggle-group-control/as-radio-group.js.map +1 -1
  20. package/build-module/composite/group-label.js +7 -1
  21. package/build-module/composite/group-label.js.map +1 -1
  22. package/build-module/composite/group.js +7 -1
  23. package/build-module/composite/group.js.map +1 -1
  24. package/build-module/composite/hover.js +8 -2
  25. package/build-module/composite/hover.js.map +1 -1
  26. package/build-module/composite/index.js +5 -1
  27. package/build-module/composite/index.js.map +1 -1
  28. package/build-module/composite/item.js +16 -1
  29. package/build-module/composite/item.js.map +1 -1
  30. package/build-module/composite/row.js +7 -1
  31. package/build-module/composite/row.js.map +1 -1
  32. package/build-module/composite/typeahead.js +8 -2
  33. package/build-module/composite/typeahead.js.map +1 -1
  34. package/build-module/date-time/date/index.js +4 -2
  35. package/build-module/date-time/date/index.js.map +1 -1
  36. package/build-module/toggle-group-control/toggle-group-control/as-radio-group.js +3 -1
  37. package/build-module/toggle-group-control/toggle-group-control/as-radio-group.js.map +1 -1
  38. package/build-types/composite/group-label.d.ts.map +1 -1
  39. package/build-types/composite/index.d.ts.map +1 -1
  40. package/build-types/composite/item.d.ts.map +1 -1
  41. package/build-types/composite/test/index.d.ts +2 -0
  42. package/build-types/composite/test/index.d.ts.map +1 -0
  43. package/build-types/date-time/date/index.d.ts.map +1 -1
  44. package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts.map +1 -1
  45. package/package.json +2 -2
  46. package/src/composite/group-label.tsx +7 -5
  47. package/src/composite/group.tsx +7 -7
  48. package/src/composite/hover.tsx +7 -7
  49. package/src/composite/index.tsx +6 -1
  50. package/src/composite/item.tsx +19 -1
  51. package/src/composite/row.tsx +7 -7
  52. package/src/composite/test/index.tsx +123 -0
  53. package/src/composite/typeahead.tsx +7 -7
  54. package/src/date-time/date/index.tsx +2 -0
  55. package/src/toggle-group-control/toggle-group-control/as-radio-group.tsx +2 -0
  56. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,123 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { queryByAttribute, render, screen } from '@testing-library/react';
5
+ import { click, press, waitFor } from '@ariakit/test';
6
+ import type { ComponentProps } from 'react';
7
+
8
+ /**
9
+ * WordPress dependencies
10
+ */
11
+ import { useState } from '@wordpress/element';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { Composite } from '..';
17
+
18
+ // This is necessary because of how Ariakit calculates page up and
19
+ // page down. Without this, nothing has a height, and so paging up
20
+ // and down doesn't behave as expected in tests.
21
+
22
+ let clientHeightSpy: jest.SpiedGetter<
23
+ typeof HTMLElement.prototype.clientHeight
24
+ >;
25
+
26
+ beforeAll( () => {
27
+ clientHeightSpy = jest
28
+ .spyOn( HTMLElement.prototype, 'clientHeight', 'get' )
29
+ .mockImplementation( function getClientHeight( this: HTMLElement ) {
30
+ if ( this.tagName === 'BODY' ) {
31
+ return window.outerHeight;
32
+ }
33
+ return 50;
34
+ } );
35
+ } );
36
+
37
+ afterAll( () => {
38
+ clientHeightSpy?.mockRestore();
39
+ } );
40
+
41
+ async function renderAndValidate( ...args: Parameters< typeof render > ) {
42
+ const view = render( ...args );
43
+ await waitFor( () => {
44
+ const activeButton = queryByAttribute(
45
+ 'data-active-item',
46
+ view.baseElement,
47
+ 'true'
48
+ );
49
+ expect( activeButton ).not.toBeNull();
50
+ } );
51
+ return view;
52
+ }
53
+
54
+ function RemoveItemTest( props: ComponentProps< typeof Composite > ) {
55
+ const [ showThirdItem, setShowThirdItem ] = useState( true );
56
+ return (
57
+ <>
58
+ <button>Focus trap before composite</button>
59
+ <Composite { ...props }>
60
+ <Composite.Item>Item 1</Composite.Item>
61
+ <Composite.Item>Item 2</Composite.Item>
62
+ { showThirdItem && <Composite.Item>Item 3</Composite.Item> }
63
+ </Composite>
64
+ <button onClick={ () => setShowThirdItem( ( value ) => ! value ) }>
65
+ Toggle third item
66
+ </button>
67
+ </>
68
+ );
69
+ }
70
+
71
+ describe( 'Composite', () => {
72
+ it( 'should remain focusable even when there are no elements in the DOM associated with the currently active ID', async () => {
73
+ await renderAndValidate( <RemoveItemTest /> );
74
+
75
+ const toggleButton = screen.getByRole( 'button', {
76
+ name: 'Toggle third item',
77
+ } );
78
+
79
+ await press.Tab();
80
+ await press.Tab();
81
+
82
+ expect(
83
+ screen.getByRole( 'button', { name: 'Item 1' } )
84
+ ).toHaveFocus();
85
+
86
+ await press.ArrowRight();
87
+ await press.ArrowRight();
88
+
89
+ expect(
90
+ screen.getByRole( 'button', { name: 'Item 3' } )
91
+ ).toHaveFocus();
92
+
93
+ await click( toggleButton );
94
+
95
+ expect(
96
+ screen.queryByRole( 'button', { name: 'Item 3' } )
97
+ ).not.toBeInTheDocument();
98
+
99
+ await press.ShiftTab();
100
+
101
+ expect(
102
+ screen.getByRole( 'button', { name: 'Item 2' } )
103
+ ).toHaveFocus();
104
+
105
+ await click( toggleButton );
106
+
107
+ expect(
108
+ screen.getByRole( 'button', { name: 'Item 3' } )
109
+ ).toBeVisible();
110
+
111
+ await press.ShiftTab();
112
+
113
+ expect(
114
+ screen.getByRole( 'button', { name: 'Item 2' } )
115
+ ).toHaveFocus();
116
+
117
+ await press.ArrowRight();
118
+
119
+ expect(
120
+ screen.getByRole( 'button', { name: 'Item 3' } )
121
+ ).toHaveFocus();
122
+ } );
123
+ } );
@@ -20,11 +20,11 @@ export const CompositeTypeahead = forwardRef<
20
20
  WordPressComponentProps< CompositeTypeaheadProps, 'div', false >
21
21
  >( function CompositeTypeahead( props, ref ) {
22
22
  const context = useCompositeContext();
23
- return (
24
- <Ariakit.CompositeTypeahead
25
- store={ context.store as Ariakit.CompositeStore }
26
- { ...props }
27
- ref={ ref }
28
- />
29
- );
23
+
24
+ // @ts-expect-error The store prop is undocumented and only used by the
25
+ // legacy compat layer. The `store` prop is documented, but its type is
26
+ // obfuscated to discourage its use outside of the component's internals.
27
+ const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;
28
+
29
+ return <Ariakit.CompositeRow store={ store } { ...props } ref={ ref } />;
30
30
  } );
@@ -125,6 +125,7 @@ export function DatePicker( {
125
125
  )
126
126
  );
127
127
  } }
128
+ size="compact"
128
129
  />
129
130
  <NavigatorHeading level={ 3 }>
130
131
  <strong>
@@ -150,6 +151,7 @@ export function DatePicker( {
150
151
  )
151
152
  );
152
153
  } }
154
+ size="compact"
153
155
  />
154
156
  </Navigator>
155
157
  <Calendar
@@ -10,6 +10,7 @@ import { useStoreState } from '@ariakit/react';
10
10
  */
11
11
  import { useInstanceId } from '@wordpress/compose';
12
12
  import { forwardRef, useMemo } from '@wordpress/element';
13
+ import { isRTL } from '@wordpress/i18n';
13
14
 
14
15
  /**
15
16
  * Internal dependencies
@@ -65,6 +66,7 @@ function UnforwardedToggleGroupControlAsRadioGroup(
65
66
  defaultValue,
66
67
  value,
67
68
  setValue: wrappedOnChangeProp,
69
+ rtl: isRTL(),
68
70
  } );
69
71
 
70
72
  const selectedValue = useStoreState( radio, 'value' );