Skip to content

Commit

Permalink
renamed onRequestClose to requestClose
Browse files Browse the repository at this point in the history
  • Loading branch information
danrot committed Aug 29, 2017
1 parent e6753cb commit a391c12
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class GenericSelect extends React.PureComponent<Props> {
};

handleDisplayValueClick = this.openList;
handleListRequestClose = this.closeList;
handleListClose = this.closeList;
setDisplayValue = (displayValue: ?ElementRef<typeof DisplayValue>) => this.displayValue = displayValue;

render() {
Expand All @@ -68,7 +68,7 @@ export default class GenericSelect extends React.PureComponent<Props> {
anchorHeight={displayValueDimensions.height}
isOpen={this.isOpen}
centeredChildIndex={this.centeredChildIndex}
onRequestClose={this.handleListRequestClose}>
onClose={this.handleListClose}>
{listChildren}
</OverlayList>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import OverlayListPositioner from './OverlayListPositioner';
type Props = {
isOpen: boolean,
children: SelectChildren,
onRequestClose?: () => void,
onClose?: () => void,
/** The top coordinate relative to which the list will be positioned */
anchorTop: number,
/** The left coordinate relative to which the list will be positioned */
Expand Down Expand Up @@ -50,13 +50,13 @@ export default class OverlayList extends React.PureComponent<Props> {
}

componentDidMount() {
window.addEventListener('blur', this.requestClose);
window.addEventListener('resize', this.requestClose);
window.addEventListener('blur', this.close);
window.addEventListener('resize', this.close);
}

componentWillUnmount() {
window.removeEventListener('blur', this.requestClose);
window.removeEventListener('resize', this.requestClose);
window.removeEventListener('blur', this.close);
window.removeEventListener('resize', this.close);
}

@action componentWillReceiveProps(newProps: Props) {
Expand All @@ -73,9 +73,9 @@ export default class OverlayList extends React.PureComponent<Props> {
});
}

requestClose = () => {
if (this.props.isOpen && this.props.onRequestClose) {
this.props.onRequestClose();
close = () => {
if (this.props.isOpen && this.props.onClose) {
this.props.onClose();
}
};

Expand Down Expand Up @@ -110,7 +110,7 @@ export default class OverlayList extends React.PureComponent<Props> {
}));
};

handleBackropClick = this.requestClose;
handleBackropClick = this.close;

render() {
let style = {opacity: '0'};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,28 @@ test('The list should not render in body when not open', () => {
});

test('The list should request to be closed when the backdrop is clicked', () => {
const onRequestCloseSpy = jest.fn();
const onCloseSpy = jest.fn();
const list = shallow(
<OverlayList isOpen={true} onRequestClose={onRequestCloseSpy}>
<OverlayList isOpen={true} onClose={onCloseSpy}>
<Option value="option-1">My option 1</Option>
</OverlayList>
);
list.find('Backdrop').simulate('click');
expect(onRequestCloseSpy).toBeCalled();
expect(onCloseSpy).toBeCalled();
});

test('The list should request to be closed when the window is blurred', () => {
const windowListeners = {};
window.addEventListener = jest.fn((event, cb) => windowListeners[event] = cb);
const onRequestCloseSpy = jest.fn();
const onCloseSpy = jest.fn();
mount(
<OverlayList isOpen={true} onRequestClose={onRequestCloseSpy}>
<OverlayList isOpen={true} onClose={onCloseSpy}>
<Option value="option-1">My option 1</Option>
</OverlayList>
).render();
expect(windowListeners.blur).toBeDefined();
windowListeners.blur();
expect(onRequestCloseSpy).toBeCalled();
expect(onCloseSpy).toBeCalled();
});

test('The list should take its dimensions from the positioner', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Props = {
confirmText: string,
onConfirm: () => void,
isOpen: boolean,
onRequestClose: () => void,
onClose: () => void,
};

const CLOSE_ICON = 'times';
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class Overlay extends React.PureComponent<Props> {
}

close = () => {
this.props.onRequestClose();
this.props.onClose();
};

@action toggle() {
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class Overlay extends React.PureComponent<Props> {
</footer>
</section>
</div>
<Backdrop local={true} onClick={this.props.onRequestClose} />
<Backdrop local={true} onClick={this.props.onClose} />
</div>
</Portal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const onConfirm = () => {
<button onClick={() => setState({open: true})}>Open overlay</button>
<Overlay
title="Njan Njan Njan"
onRequestClose={() => setState({open: false})}
onClose={() => setState({open: false})}
actions={actions}
confirmText="Apply"
onConfirm={onConfirm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ afterEach(() => document.body.innerHTML = '');

test('The component should render in body when open', () => {
const body = document.body;
const onRequestClose = () => {};
const onClose = () => {};
const view = mount(
<Overlay
title="My overlay title"
onRequestClose={onRequestClose}
onClose={onClose}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
Expand All @@ -30,11 +30,11 @@ test('The component should render in body with actions when open', () => {
{title: 'Action 2', onClick: () => {}},
];
const body = document.body;
const onRequestClose = () => {};
const onClose = () => {};
const view = mount(
<Overlay
title="My overlay title"
onRequestClose={onRequestClose}
onClose={onClose}
confirmText="Apply"
actions={actions}
isOpen={true}>
Expand All @@ -48,11 +48,11 @@ test('The component should render in body with actions when open', () => {

test('The component should not render in body when closed', () => {
const body = document.body;
const onRequestClose = () => {};
const onClose = () => {};
const view = mount(
<Overlay
title="My overlay title"
onRequestClose={onRequestClose}
onClose={onClose}
confirmText="Apply"
isOpen={false}>
<p>My overlay content</p>
Expand All @@ -63,11 +63,11 @@ test('The component should not render in body when closed', () => {
});

test('The component should request to be closed on click on backdrop', () => {
const requestCloseSpy = jest.fn();
const closeSpy = jest.fn();
const view = shallow(
<Overlay
title="My overlay title"
onRequestClose={requestCloseSpy}
onClose={closeSpy}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
Expand All @@ -76,52 +76,52 @@ test('The component should request to be closed on click on backdrop', () => {
const backdrop = view.find('Backdrop');
expect(backdrop.length).toBe(1);

expect(requestCloseSpy).not.toBeCalled();
expect(closeSpy).not.toBeCalled();
backdrop.props().onClick();
expect(requestCloseSpy).toBeCalled();
expect(closeSpy).toBeCalled();
});

test('The component should request to be closed when the close icon is clicked', () => {
const requestCloseSpy = jest.fn();
const closeSpy = jest.fn();
const view = shallow(
<Overlay
title="My overlay title"
onRequestClose={requestCloseSpy}
onClose={closeSpy}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
</Overlay>
);

expect(requestCloseSpy).not.toBeCalled();
expect(closeSpy).not.toBeCalled();
view.find('Icon').simulate('click');
expect(requestCloseSpy).toBeCalled();
expect(closeSpy).toBeCalled();
});

test('The component should request to be closed when the esc key is pressed', () => {
const requestCloseSpy = jest.fn();
const closeSpy = jest.fn();
mount(
<Overlay
title="My overlay title"
onRequestClose={requestCloseSpy}
onClose={closeSpy}
confirmText="Apply"
isOpen={true}>
<p>My overlay content</p>
</Overlay>
);

expect(requestCloseSpy).not.toBeCalled();
expect(closeSpy).not.toBeCalled();
Mousetrap.trigger('esc');
expect(requestCloseSpy).toBeCalled();
expect(closeSpy).toBeCalled();
});

test('The component should call the callback when the confirm button is clicked', () => {
const onRequestClose = () => {};
const onClose = () => {};
const onConfirm = jest.fn();
const view = shallow(
<Overlay
title="My title"
onRequestClose={onRequestClose}
onClose={onClose}
onConfirm={onConfirm}
confirmText="Alright mate!">
<p>My overlay content</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Dropdown extends React.PureComponent<DropdownProps> {
<OptionList
options={options}
onOptionClick={this.handleOptionListClick}
onRequestClose={this.handleOptionListClose} />
onClose={this.handleOptionListClose} />
}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
onOptionClick: (option: Object) => void,
value?: string | number,
size?: string,
onRequestClose?: () => void,
onClose?: () => void,
options: Array<Object>,
};

Expand All @@ -19,14 +19,14 @@ export default class OptionList extends React.PureComponent<Props> {
this.props.onOptionClick(option);
}

if (this.props.onRequestClose) {
this.props.onRequestClose();
if (this.props.onClose) {
this.props.onClose();
}
};

handleBackdropClick = () => {
if (this.props.onRequestClose) {
this.props.onRequestClose();
if (this.props.onClose) {
this.props.onClose();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Select extends React.PureComponent<SelectProps> {
value={value}
options={options}
onOptionClick={this.handleOptionClick}
onRequestClose={this.handleOptionListClose} />
onClose={this.handleOptionListClose} />
}
</div>
);
Expand Down

0 comments on commit a391c12

Please sign in to comment.