Skip to content

Commit ad4a342

Browse files
authored
docs: update for v0.10 (floating-ui#1892)
1 parent f0404c4 commit ad4a342

File tree

3 files changed

+103
-53
lines changed

3 files changed

+103
-53
lines changed

website/pages/docs/FloatingFocusManager.mdx

+34-37
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ interface Props {
3737
| number
3838
| React.MutableRefObject<HTMLElement | null>;
3939
returnFocus?: boolean;
40-
preventTabbing?: boolean;
4140
endGuard?: boolean;
4241
modal?: boolean;
4342
}
@@ -85,9 +84,6 @@ Which element to initially focus. Can be either a number
8584
(tabbable index as specified by the `order{:.objectKey}`) or a
8685
ref.
8786

88-
> This does not have an effect when `preventTabbing{:.keyword}`
89-
> is enabled.
90-
9187
```js
9288
<FloatingFocusManager
9389
context={context}
@@ -105,35 +101,12 @@ Determines if focus should be returned to the element that was
105101
focused prior to opening the floating element (usually the
106102
reference element).
107103

108-
> This does not have an effect when `preventTabbing{:.keyword}`
109-
> is enabled.
110-
111104
```js
112105
<FloatingFocusManager context={context} returnFocus={false}>
113106
{/* floating element */}
114107
</FloatingFocusManager>
115108
```
116109

117-
### preventTabbing
118-
119-
default: `false{:js}`
120-
121-
Determines if the tab key does not perform any action, so that
122-
focus cannot escape the floating element. Focus is instead
123-
handled by `useListNavigation(){:js}` (i.e. arrow key
124-
navigation).
125-
126-
This prop is required when the focus is
127-
[modal](/docs/FloatingFocusManager#modal) and the floating
128-
element is portalled outside of the reference element's DOM
129-
context.
130-
131-
```js
132-
<FloatingFocusManager context={context} preventTabbing={true}>
133-
{/* floating element */}
134-
</FloatingFocusManager>
135-
```
136-
137110
### endGuard
138111

139112
default: `true{:js}`
@@ -157,20 +130,44 @@ Determines if focus is "modal", meaning focus is fully trapped
157130
inside the floating element and outside content cannot be
158131
accessed. This includes screen reader virtual cursors.
159132

160-
> If `false{:js}`, the floating element must be rendered directly
161-
> after its reference element (e.g. not in a FloatingPortal).
162-
163133
```js
164134
<FloatingFocusManager context={context} modal={false}>
165135
{/* floating element */}
166136
</FloatingFocusManager>
167137
```
168138

169-
#### Input comboboxes
139+
#### Non-modal behavior
140+
141+
The floating element must be rendered directly after its
142+
reference element (e.g. not in a FloatingPortal) when non-modal.
143+
144+
#### Modal behavior
145+
146+
Ensure you have an explicit "close" button. This can be either
147+
visible to all users, or visually-hidden so it is only available
148+
to assistive tech.
149+
150+
Touch-based screen readers often will not have an `esc` key
151+
available to dismiss the element, so an explicit close button is
152+
required.
153+
154+
You may use the reference element as the close button with some
155+
components, so the user can navigate to it and use it as a toggle
156+
to both close and open the floating element. This can be achieved
157+
with the `order{:.keyword}` prop and adding the reference as a
158+
string.
159+
160+
#### Comboboxes
161+
162+
The listbox part of a combobox should be rendered directly after
163+
the input reference element when possible.
164+
165+
If the listbox is portaled, detection is added so that DOM focus
166+
does not become modal in this case, but screen reader virtual
167+
cursors do become modal. This ensures a touch user can swipe
168+
right (e.g. iOS screen reader) to navigate the listbox options
169+
immediately.
170170

171-
`<input />{:js}` comboboxes should not be modal when possible.
172-
When setting them to modal, focus does not become modal but
173-
screen reader virtual cursors do become modal. Therefore, the
174-
listbox should have a visually-hidden dismiss button to ensure
175-
touch-based screen reader users can escape the list without
176-
needing to select anything.
171+
As with all modal-based focus management, the listbox should have
172+
a visually-hidden dismiss button to ensure touch-based screen
173+
reader users can escape the list due to a lack of an `esc` key.

website/pages/docs/useClick.mdx

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const {getReferenceProps, getFloatingProps} = useInteractions([
2323
```js
2424
interface Props {
2525
enabled?: boolean;
26-
pointerDown?: boolean;
26+
event?: 'click' | 'mousedown';
2727
toggle?: boolean;
2828
ignoreMouse?: boolean;
2929
keyboardHandlers?: boolean;
@@ -42,17 +42,16 @@ useClick(context, {
4242
});
4343
```
4444

45-
### pointerDown
45+
### event
4646

47-
default: `false{:js}`
47+
default: `'click'{:js}`
4848

49-
Whether to prefer the `pointerdown{:.string}` event over
50-
`click{:.string}` (for faster feedback). Keyboard clicks will
51-
continue to work.
49+
The type of event to use to determine a "click" with mouse input.
50+
Keyboard clicks work as normal.
5251

5352
```js
5453
useClick(context, {
55-
pointerDown: true,
54+
event: 'mousedown',
5655
});
5756
```
5857

website/pages/docs/useDismiss.mdx

+63-9
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ const {getReferenceProps, getFloatingProps} = useInteractions([
2424
interface Props {
2525
enabled?: boolean;
2626
escapeKey?: boolean;
27-
referencePointerDown?: boolean;
28-
outsidePointerDown?: boolean;
27+
referencePress?: boolean;
28+
referencePressEvent?: 'pointerdown' | 'mousedown' | 'click';
29+
outsidePress?: boolean;
30+
outsidePressEvent?: 'pointerdown' | 'mousedown' | 'click';
2931
ancestorScroll?: boolean;
3032
bubbles?: boolean;
3133
}
@@ -56,29 +58,81 @@ useDismiss(context, {
5658
});
5759
```
5860

59-
### referencePointerDown
61+
### referencePress
6062

6163
default: `false{:js}`
6264

63-
Whether to dismiss the floating element upon pointer down of the
65+
Whether to dismiss the floating element upon pressing the
6466
reference element.
6567

6668
```js
6769
useDismiss(context, {
68-
referencePointerDown: true,
70+
referencePress: true,
6971
});
7072
```
7173

72-
### outsidePointerDown
74+
You likely want to ensure the `move{:.objectKey}` option in the
75+
`useHover(){:js}` hook has been disabled when this is in use.
76+
77+
#### Keyboard press dismissal
78+
79+
If you'd like to ensure the floating element is also dismissed
80+
upon "pressing" the reference element via the keyboard, you can
81+
add in your own handler(s) for this.
82+
83+
```js
84+
getReferenceProps({
85+
// for a native <button>
86+
onClick() {
87+
setOpen(false);
88+
},
89+
});
90+
```
91+
92+
### referencePressEvent
93+
94+
default: `'pointerdown'{:js}`
95+
96+
The type of event to use to determine a "press".
97+
98+
```js
99+
useDismiss(context, {
100+
// eager on both mouse + touch input
101+
referencePressEvent: 'pointerdown',
102+
// eager on mouse input, lazy on touch input
103+
referencePressEvent: 'mousedown',
104+
// lazy on both mouse + touch input
105+
referencePressEvent: 'click',
106+
});
107+
```
108+
109+
### outsidePress
73110

74111
default: `true{:js}`
75112

76-
Whether to dismiss the floating element upon pointer down outside
77-
of both the floating and reference elements.
113+
Whether to dismiss the floating element upon pressing outside of
114+
both the floating and reference elements.
115+
116+
```js
117+
useDismiss(context, {
118+
outsidePress: false,
119+
});
120+
```
121+
122+
### outsidePressEvent
123+
124+
default: `'pointerdown'{:js}`
125+
126+
The type of event to use to determine a "press".
78127

79128
```js
80129
useDismiss(context, {
81-
outsidePointerDown: false,
130+
// eager on both mouse + touch input
131+
outsidePressEvent: 'pointerdown',
132+
// eager on mouse input, lazy on touch input
133+
outsidePressEvent: 'mousedown',
134+
// lazy on both mouse + touch input
135+
outsidePressEvent: 'click',
82136
});
83137
```
84138

0 commit comments

Comments
 (0)