-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Remove auto focus from Modal Content #128
Conversation
…ocused when the modal opens
2. Use this prop to auto focus the first element within the modal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add another Modal story with no input and some buttons to verify?
src/Modal/Modal.js
Outdated
transitionState={state} | ||
onClick={handleContentClick} | ||
aria-modal="true" | ||
tabIndex={!autofocus && 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need this. The input in the Modal stories still autofocuses without setting to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is because the Input itself has an auto focus prop.
https://github.com/heydoctor/molekule/blob/master/src/Modal/Modal.example.js#L39
I have added an example with an input included to show that even if you have an input, the modal won't auto focus it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @Pr1ncek! Could we remove the outline on ModalContent?
Behavior of the Basic Modal has an outline already. So it takes four tabs to cycle through the elements. 1 input, 2 buttons, and the Modal itself. There are two approaches we can take here.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works great!
📃 Summary
This behavior can be unwanted sometimes. See discussion within the Asana ticket for more context.
Solution
Important Note
If you have a form within a modal and you want the first input to auto focus when the modal opens, then you have to pass the auto focus prop to the Input itself.
As shown here. https://github.com/heydoctor/molekule/blob/master/src/Modal/Modal.example.js#L39
🏷 Asana Task
https://app.asana.com/0/1172482803331797/1176612299695449/f
QA
Expect
When you open this modal, none of the elements should have focus until you press tab.
I will remove this example before merging because I don't really think this needs to be an entirely separate example in our story book.
📈 Risk Analysis