Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-12944: force "Delete" focus on showing delete post modal (#2020)
Browse files Browse the repository at this point in the history
Focus handling is a mess. This doesn't really make it much better, other than making the behaviour explicit and constrained to within the modal dialog in question, fixing a regression introduced by MM-12688.
  • Loading branch information
lieut-data committed Nov 9, 2018
1 parent 40563d5 commit ac3cf36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
24 changes: 8 additions & 16 deletions components/delete_post_modal/delete_post_modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,15 @@ export default class DeletePostModal extends React.PureComponent {
teamName: PropTypes.string,
post: PropTypes.object.isRequired,
commentCount: PropTypes.number.isRequired,

/**
* Does the post come from RHS mode
*/
isRHS: PropTypes.bool.isRequired,

/**
* Function called when modal is dismissed
*/
onHide: PropTypes.func.isRequired,

actions: PropTypes.shape({

/**
* Function called for deleting post
*/
deleteAndRemovePost: PropTypes.func.isRequired,
}),
}

constructor(props) {
super(props);
this.handleDelete = this.handleDelete.bind(this);
this.onHide = this.onHide.bind(this);
this.state = {
show: true,
};
Expand All @@ -66,7 +51,13 @@ export default class DeletePostModal extends React.PureComponent {
}
}

onHide() {
handleEntered = () => {
if (this.deletePostBtn) {
this.deletePostBtn.focus();
}
}

onHide = () => {
this.setState({show: false});

if (!UserAgent.isMobile()) {
Expand Down Expand Up @@ -111,6 +102,7 @@ export default class DeletePostModal extends React.PureComponent {
return (
<Modal
show={this.state.show}
onEntered={this.handleEntered}
onHide={this.onHide}
onExited={this.props.onHide}
enforceFocus={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`components/delete_post_modal should match snapshot for delete_post_moda
"remove": [Function],
}
}
onEntered={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
Expand Down Expand Up @@ -123,6 +124,7 @@ exports[`components/delete_post_modal should match snapshot for delete_post_moda
"remove": [Function],
}
}
onEntered={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
Expand Down
12 changes: 12 additions & 0 deletions tests/components/delete_post_modal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ describe('components/delete_post_modal', () => {
expect(wrapper).toMatchSnapshot();
});

test('should focus delete button on enter', () => {
const wrapper = shallow(
<DeletePostModal {...baseProps}/>
);

const deletePostBtn = {focus: jest.fn()};
wrapper.instance().deletePostBtn = deletePostBtn;

wrapper.instance().handleEntered();
expect(deletePostBtn.focus).toHaveBeenCalled();
});

test('should match state when onHide is called', () => {
const wrapper = shallow(
<DeletePostModal {...baseProps}/>
Expand Down

0 comments on commit ac3cf36

Please sign in to comment.