Skip to content

Commit e17e67f

Browse files
authored
docs: Add a ref to the second argument of useButton (#1298)
1 parent 0b42aed commit e17e67f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/@react-aria/dialog/docs/useDialog.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,22 @@ function ModalDialog(props) {
165165

166166
function Example() {
167167
let state = useOverlayTriggerState({});
168+
let openButtonRef = React.useRef();
169+
let closeButtonRef = React.useRef();
168170

169171
// useButton ensures that focus management is handled correctly,
170172
// across all browsers. Focus is restored to the button once the
171173
// dialog closes.
172174
let {buttonProps: openButtonProps} = useButton({
173175
onPress: () => state.open()
174-
});
176+
}, openButtonRef);
175177

176178
let {buttonProps: closeButtonProps} = useButton({
177179
onPress: () => state.close()
178-
});
180+
}, closeButtonRef);
179181

180182
return <>
181-
<button {...openButtonProps}>Open Dialog</button>
183+
<button {...openButtonProps} ref={openButtonRef}>Open Dialog</button>
182184
{state.isOpen &&
183185
<OverlayContainer>
184186
<ModalDialog
@@ -195,6 +197,7 @@ function Example() {
195197
</label>
196198
<button
197199
{...closeButtonProps}
200+
ref={closeButtonRef}
198201
style={{marginTop: 10}}>
199202
Submit
200203
</button>

packages/@react-aria/overlays/docs/useOverlayTrigger.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function Example() {
195195
// popover closes.
196196
let {buttonProps} = useButton({
197197
onPress: () => state.open()
198-
});
198+
}, triggerRef);
199199

200200
return <>
201201
<button

0 commit comments

Comments
 (0)