-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixed] corretly walk when using TAB.
closes #511.
- Loading branch information
Showing
3 changed files
with
103 additions
and
71 deletions.
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 |
---|---|---|
@@ -1,96 +1,78 @@ | ||
import React, { Component } from 'react'; | ||
import Modal from 'react-modal'; | ||
import MyModal from './modal'; | ||
|
||
const MODAL_A = 'modal_a'; | ||
const MODAL_B = 'modal_b'; | ||
|
||
const DEFAULT_TITLE = 'Default title'; | ||
|
||
class SimpleUsage extends Component { | ||
class Forms extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
title1: DEFAULT_TITLE, | ||
currentModal: null | ||
}; | ||
} | ||
|
||
toggleModal = key => event => { | ||
event.preventDefault(); | ||
if (this.state.currentModal) { | ||
this.handleModalCloseRequest(); | ||
return; | ||
} | ||
|
||
this.setState({ | ||
...this.state, | ||
currentModal: key, | ||
title1: DEFAULT_TITLE | ||
}); | ||
} | ||
|
||
handleModalCloseRequest = () => { | ||
// opportunity to validate something and keep the modal open even if it | ||
// requested to be closed | ||
this.setState({ | ||
...this.state, | ||
currentModal: null | ||
}); | ||
} | ||
|
||
handleInputChange = e => { | ||
let text = e.target.value; | ||
if (text == '') { | ||
text = DEFAULT_TITLE; | ||
} | ||
this.setState({ ...this.state, title1: text }); | ||
this.state = { isOpen: false }; | ||
} | ||
|
||
handleOnAfterOpenModal = () => { | ||
// when ready, we can access the available refs. | ||
this.heading && (this.heading.style.color = '#F00'); | ||
toggleModal = event => { | ||
console.log(event); | ||
const { isOpen } = this.state; | ||
this.setState({ isOpen: !isOpen }); | ||
} | ||
|
||
headingRef = h1 => this.heading = h1; | ||
|
||
render() { | ||
const { currentModal } = this.state; | ||
const { isOpen } = this.state; | ||
|
||
return ( | ||
<div> | ||
<button onClick={this.toggleModal(MODAL_A)}>Open Modal A</button> | ||
<button onClick={this.toggleModal(MODAL_B)}>Open Modal B</button> | ||
<MyModal | ||
title={this.state.title1} | ||
isOpen={currentModal == MODAL_A} | ||
onAfterOpen={this.handleOnAfterOpenModal} | ||
onRequestClose={this.handleModalCloseRequest} | ||
askToClose={this.toggleModal(MODAL_A)} | ||
onChangeInput={this.handleInputChange} /> | ||
<button className="btn btn-primary" onClick={this.toggleModal}>Open Modal</button> | ||
<Modal | ||
ref="mymodal2" | ||
id="test2" | ||
id="modal_with_forms" | ||
isOpen={isOpen} | ||
closeTimeoutMS={150} | ||
contentLabel="modalB" | ||
shouldCloseOnOverlayClick={true} | ||
onRequestClose={this.toggleModal} | ||
aria={{ | ||
labelledby: "heading", | ||
describedby: "fulldescription" | ||
}} | ||
closeTimeoutMS={150} | ||
contentLabel="modalB" | ||
isOpen={currentModal == MODAL_B} | ||
onAfterOpen={this.handleOnAfterOpenModal} | ||
onRequestClose={this.toggleModal(MODAL_B)}> | ||
<h1 id="heading" ref={headingRef}>This is the modal 2!</h1> | ||
}}> | ||
<h1 id="heading">Forms!</h1> | ||
<div id="fulldescription" tabIndex="0" role="document"> | ||
<p>This is a description of what it does: nothing :)</p> | ||
</div>p | ||
|
||
<form> | ||
<fieldset> | ||
<input type="text" /> | ||
<input type="text" /> | ||
</fieldset> | ||
<fieldset> | ||
<legend>Radio buttons</legend> | ||
<label> | ||
<input id="radio-a" name="radios" type="radio" /> A | ||
</label> | ||
<label> | ||
<input id="radio-b" name="radios" type="radio" /> B | ||
</label> | ||
</fieldset> | ||
<fieldset> | ||
<legend>Checkbox buttons</legend> | ||
<label> | ||
<input id="checkbox-a" name="checkbox-a" type="checkbox" /> A | ||
</label> | ||
<label> | ||
<input id="checkbox-b" name="checkbox-b" type="checkbox" /> B | ||
</label> | ||
</fieldset> | ||
<input type="text" /> | ||
</form> | ||
</div> | ||
</Modal> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default { | ||
label: "#1. Working with one modal at a time.", | ||
app: SimpleUsage | ||
label: "#3. Modal with forms fields.", | ||
app: Forms | ||
}; |
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