Skip to content

Commit

Permalink
[chore] fix multiple modal example.
Browse files Browse the repository at this point in the history
  • Loading branch information
diasbruno committed Sep 23, 2017
1 parent ce2b34e commit d896241
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions examples/basic/multiple_modals/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React, { Component } from 'react';
import Modal from 'react-modal';

function List(props) {
return props.items.map((x, i) => (
<div key={i} onClick={props.onItemClick(i)}>
<a href="javascript:void(0)">{x}</a>
</div>
));
class List extends React.Component {
render() {
return (
<div>
{this.props.items.map((x, i) => (
<div key={i} onClick={this.props.onItemClick(i)}>
<a href="javascript:void(0)">{x}</a>
</div>))}
</div>
);
}
}

class MultipleModals extends Component {
Expand All @@ -27,7 +32,6 @@ class MultipleModals extends Component {
return;
}
this.setState({
...this.state,
items: [],
listItemsIsOpen: true,
loading: true
Expand All @@ -38,7 +42,6 @@ class MultipleModals extends Component {
// opportunity to validate something and keep the modal open even if it
// requested to be closed
this.setState({
...this.state,
listItemsIsOpen: false,
loading: false
});
Expand All @@ -47,22 +50,21 @@ class MultipleModals extends Component {
handleOnAfterOpenModal = () => {
// when ready, we can access the available refs.
(new Promise((resolve, reject) => {
setTimeout(() => resolve(true), 1000);
setTimeout(() => resolve(true), 500);
})).then(res => {
this.setState({
...this.state,
items: [1, 2, 3, 4, 5].map(x => `Item ${x}`),
loading: false
});
});
}

onItemClick = index => event => {
this.setState({ ...this.state, currentItem: index });
this.setState({ currentItem: index });
}

cleanCurrentItem = () => {
this.setState({ ...this.state, currentItem: -1 });
this.setState({ currentItem: -1 });
}

render() {
Expand Down

0 comments on commit d896241

Please sign in to comment.