You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,45 @@
1
1
# @primer/components
2
2
3
+
## 27.0.0
4
+
5
+
### Major Changes
6
+
7
+
-[`db478205`](https://github.com/primer/components/commit/db478205bf467a118394e0519034bb87116dc85a)[#1147](https://github.com/primer/components/pull/1147) Thanks [@colebemis](https://github.com/colebemis)! - Type definitions are now being generated by TypeScript instead of manually maintained. These new type definitions may differ from the previous type definitions and cause breaking changes. If you experience any new TypeScript errors, feel free to create an [issue](https://github.com/primer/components/issues) or reach out in Slack (#design-systems).
8
+
9
+
### Breaking changes
10
+
11
+
- The following types are no longer exported:
12
+
13
+
```
14
+
BaseProps
15
+
UseDetailsProps
16
+
AnchoredPositionHookSettings
17
+
AnchorAlignment
18
+
AnchorSide
19
+
PositionSettings
20
+
PaginationHrefBuilder
21
+
PaginationPageChangeCallback
22
+
PositionComponentProps
23
+
```
24
+
25
+
- Props are now defined with types instead of interfaces which means in some cases you may not be able to create interfaces that `extend` them. To work around this issue, you may need to convert your interfaces to types:
26
+
27
+
```diff
28
+
import {BoxProps} from '@primer/components'
29
+
30
+
- interface MyFancyBox extends BoxProps {...}
31
+
+ type MyFancyBox = BoxProps & {...}
32
+
```
33
+
34
+
- Some components now expect more specific ref types. For example:
Copy file name to clipboardExpand all lines: docs/content/focusZone.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ For a more customized focus movement behavior, the consumer has the ability to s
24
24
25
25
By default, when focus enters a focus zone, the element that receives focus will be the most recently-focused element within that focus zone. If no element had previously been focused, or if that previously-focused element was removed, focus will revert to the first focusable element within the focus zone, regardless of the direction of focus movement.
26
26
27
-
Using the `focusInStrategy` option, you can change this behavior. Setting this option to `"first"` will simply cause the first focusable element in the container to be focused whenever focus enters the focus zone. Otherwise, you may provide a callback to choose a custom element to receive initial focus. One scenario where this would be useful is if you wanted to focus an item that is "selected" in a list.
27
+
Using the `focusInStrategy` option, you can change this behavior. Setting this option to `"first"` will simply cause the first focusable element in the container to be focused whenever focus enters the focus zone. Setting it to `"closest"` will cause either the first or last focusable element in the container to be focused depending on the direction of focus movement (for example, a shift+tab that brings focus to the container will cause the last focusable element to be focused, whereas a regular tab would cause the first focusable element to be focused). Otherwise, you may provide a callback to choose a custom element to receive initial focus. One scenario where this would be useful is if you wanted to focus an item that is "selected" in a list.
28
28
29
29
For more information on choosing the right focus in behavior, see [6.6 Keyboard Navigation Inside Components](https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_general_within) from the ARIA Authoring Practices document.
30
30
@@ -81,7 +81,7 @@ The `focusZone` function takes the following arguments.
81
81
| :- | :- | :-: | :- |
82
82
| bindKeys |`FocusKeys` (numeric enum) |`FocusKeys.ArrowVertical`|`FocusKeys.HomeAndEnd`| Bit flags that identify keys that will move focus around the focus zone. Each available key either moves focus to the "next", "previous", "start", or "end" element, so it is best to only bind the keys that make sense to move focus in your UI. Use the `FocusKeys` object to discover supported keys (listed in the "Supported keys" section above). <br /><br />Use the bitwise "OR" operator (|) to combine key types. For example, `FocusKeys.WASD`|`FocusKeys.HJKL` represents all of W, A, S, D, H, J, K, and L.<br /><br />The default for this setting is `FocusKeys.ArrowVertical`|`FocusKeys.HomeAndEnd`, unless `getNextFocusable` is provided, in which case `FocusKeys.ArrowAll`|`FocusKeys.HomeAndEnd` is used as the default. |
83
83
| focusOutBehavior |`"stop"`|`"wrap"`|`"stop"`| Choose the behavior applied in cases where focus is currently at either the first or last element of the container. `"stop"` - do nothing and keep focus where it was; `"wrap"` - wrap focus around to the first element from the last, or the last element from the first |
84
-
| focusInStrategy |`"first"`|`"previous"`|`Function`|`"previous"`| This option allows customization of the behavior that determines which of the focusable elements should be focused when focus enters the container via the Tab key.<br /><br />When set to `"first"`, whenever focus enters the container via Tab, we will focus the first focusable element. When set to `"previous"`, the most recently focused element will be focused (fallback to first if there was no previous).<br /><br />If a function is provided, this function should return the `HTMLElement` intended to receive focus. This is useful if you want to focus the currently "selected" item or element. |
84
+
| focusInStrategy |`"first"`|`"closest"`|`"previous"`|`Function`|`"previous"`| This option allows customization of the behavior that determines which of the focusable elements should be focused when focus enters the container via the Tab key.<br /><br />When set to `"first"`, whenever focus enters the container via Tab, we will focus the first focusable element. When set to `"previous"`, the most recently focused element will be focused (fallback to first if there was no previous).<br /><br />The "closest" strategy works like "first", except either the first or the last element of the container will be focused, depending on the direction from which focus comes.<br /><br />If a function is provided, this function should return the `HTMLElement` intended to receive focus. This is useful if you want to focus the currently "selected" item or element. |
85
85
| getNextFocusable |`Function`|| This is a callback used to customize the next element to focus when a bound key is pressed. The function takes 3 arguments: `direction` (`"previous"`, `"next"`, `"start"`, or `"end"`), `from` (Element or `undefined`), and `event` (KeyboardEvent). The function should return the next element to focus, or `undefined`. If `undefined` is returned, the regular algorithm to select the next element to focus will be used. |
86
86
| focusableElementFilter |`Function`|| This is a callback used to cull focusable elements from participating in the focus zone. |
87
87
| abortSignal |`AbortSignal`|| If passed, the focus zone will be deactivated and all event listeners removed when this signal is aborted. If not passed, an `AbortSignal` will be returned by the `focusZone` function. |
Copy file name to clipboardExpand all lines: docs/content/useOnEscapePress.mdx
+22-7Lines changed: 22 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,22 @@
2
2
title: useOnEscapePress
3
3
---
4
4
5
-
`useOnEscapePress` is a simple utility Hook that calls a user provided function when the `Escape` key is pressed.
5
+
`useOnEscapePress` is a simple utility Hook that calls a user-provided function when the `Escape` key is pressed. The hook sets up `keydown` event listener on `window.document` and executes the user-provided function if these conditions are met:
6
+
7
+
1. The Escape key was pressed
8
+
2. The `preventDefault` method has not yet been called on the event object.
9
+
10
+
Furthermore, unlike the normal behavior for multiple event listeners existing on the same DOM Node, if multiple `useOnEscapePress` hooks are active simultaneously, the callbacks will occur in reverse order. In other words, if a parent component and a child component both call `useOnEscapePress`, when the user presses Escape, the child component's callback will execute, followed by the parent's callback. Each callback has the chance to call `.preventDefault()` on the event to prevent further callbacks.
11
+
12
+
### Dependencies
13
+
14
+
Similar to `useCallback`, `useOnEscapePress` takes a `React.DependencyList` as its second argument. These are the dependencies used to memoize the callback. Failing to provide the correct dependency list can result in degraded performance. If this argument is omitted, we will assume that the callback is already memoized. In the example below, that memoization occurs in `DemoComponent` with a call to `React.useCallback`, so `OverlayDemo` does not need to pass a dependency list.
0 commit comments