File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
packages/react/src/Dialog Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 59
59
"name" : " returnFocusRef" ,
60
60
"type" : " React.RefObject<HTMLElement>" ,
61
61
"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"
62
67
}
63
68
],
64
69
"subcomponents" : []
Original file line number Diff line number Diff line change @@ -209,3 +209,21 @@ describe('Dialog', () => {
209
209
expect ( getByRole ( 'button' , { name : 'return focus to (button 2)' } ) ) . toHaveFocus ( )
210
210
} )
211
211
} )
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
+ } )
You can’t perform that action at this time.
0 commit comments