This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Remove auto focus from Modal Content (#128)
* 1. Add tabindex to modal content, so elements are not automatically focused when the modal opens * 1. Add an autofocus prop to the Modal 2. Use this prop to auto focus the first element within the modal * Prevent auto focus by setting tab index * Add an example with no autofocus * Remove focus outline from Modal
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import Modal from './Modal'; | ||
import Button from '../Button'; | ||
import Input from '../Form/Input'; | ||
|
||
export default class ModalNoAutoFocusExample extends React.Component { | ||
state = { | ||
isModalOpen: false, | ||
isModalTwoOpen: false, | ||
}; | ||
|
||
toggle = () => { | ||
this.setState({ isModalOpen: !this.state.isModalOpen, isModalTwoOpen: false }); | ||
}; | ||
|
||
toggleModalTwo = () => { | ||
this.setState({ isModalTwoOpen: !this.state.isModalTwoOpen }); | ||
}; | ||
|
||
onCancel = () => { | ||
this.toggle(); | ||
|
||
setTimeout(() => { | ||
alert('Oh no! It has been canceled.'); | ||
}, 500); | ||
}; | ||
|
||
render() { | ||
const { body, bodyTwo = 'Im a nested modal!', ...props } = this.props; | ||
|
||
return ( | ||
<div> | ||
<Button onClick={this.toggle}>Open Modal</Button> | ||
|
||
<Modal open={this.state.isModalOpen} onClose={this.toggle} title="Example Modal" {...props}> | ||
<Modal.Body> | ||
<> | ||
{body} | ||
<Input name="password" label="Password" /> | ||
</> | ||
|
||
<Modal open={this.state.isModalTwoOpen} onClose={this.toggleModalTwo} title="Example Modal Two" {...props}> | ||
<Modal.Body>{bodyTwo}</Modal.Body> | ||
|
||
<Modal.Footer> | ||
<Button.Group justifyContent="space-between"> | ||
<Button variant="grey" onClick={this.toggleModalTwo}> | ||
Cancel | ||
</Button> | ||
<Button variant="success" onClick={this.toggleModalTwo}> | ||
I'm Done Anyways | ||
</Button> | ||
</Button.Group> | ||
</Modal.Footer> | ||
</Modal> | ||
</Modal.Body> | ||
|
||
<Modal.Footer> | ||
<Button.Group justifyContent="space-between"> | ||
<Button variant="grey" onClick={this.onCancel}> | ||
Cancel | ||
</Button> | ||
<Button variant="success" onClick={this.toggleModalTwo}> | ||
Open Another Modal | ||
</Button> | ||
</Button.Group> | ||
</Modal.Footer> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters