Skip to content

Commit f7ecb5e

Browse files
add test and docs
1 parent c98e4f5 commit f7ecb5e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/react/src/Dialog/Dialog.docs.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"name": "returnFocusRef",
6060
"type": "React.RefObject<HTMLElement>",
6161
"describedby": "Return focus to this element when the Dialog closes, instead of the element that had focus immediately before the Dialog opened"
62+
},
63+
{
64+
"name": "initialFocusRef",
65+
"type": "React.RefObject<HTMLElement>",
66+
"description": "Focus this element when the Dialog opens"
6267
}
6368
],
6469
"subcomponents": []

packages/react/src/Dialog/Dialog.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,21 @@ describe('Dialog', () => {
209209
expect(getByRole('button', {name: 'return focus to (button 2)'})).toHaveFocus()
210210
})
211211
})
212+
213+
it('automatically focuses the element that is specified as initialFocusRef', () => {
214+
const initialFocusRef = React.createRef<HTMLAnchorElement>()
215+
const {getByRole} = render(
216+
<Dialog
217+
initialFocusRef={initialFocusRef}
218+
onClose={() => {}}
219+
title="New issue"
220+
renderBody={() => (
221+
<a ref={initialFocusRef} href="https://github.com">
222+
Item 1
223+
</a>
224+
)}
225+
></Dialog>,
226+
)
227+
228+
expect(getByRole('link')).toHaveFocus()
229+
})

0 commit comments

Comments
 (0)