diff --git a/CHANGELOG.md b/CHANGELOG.md index 98d28bc6c7a..9b13f60516f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ - Added initial sorting option to `EuiInMemoryTable` ([#547](https://github.com/elastic/eui/pull/547)) +**Bug fixes** + +- `EuiConfirmModal` will now check for the presence of confirm and cancel buttons before trying to focus them ([#555](https://github.com/elastic/eui/pull/555)) + # [`0.0.32`](https://github.com/elastic/eui/tree/v0.0.32) - Updated `EuiDescriptionList` to accept nodes for the titles and descriptions ([#552](https://github.com/elastic/eui/pull/552)) diff --git a/src/components/modal/confirm_modal.js b/src/components/modal/confirm_modal.js index 5b6f19db31b..d39fc7a6787 100644 --- a/src/components/modal/confirm_modal.js +++ b/src/components/modal/confirm_modal.js @@ -31,11 +31,12 @@ export class EuiConfirmModal extends Component { // elements conflicts with the focus-trap logic we have on EuiModal. const { defaultFocusedButton } = this.props; - // Wait a beat for the focus-trap to complete, and then set focus to the right button. + // Wait a beat for the focus-trap to complete, and then set focus to the right button. Check that + // the buttons exist first, because it's possible the modal has been closed already. requestAnimationFrame(() => { - if (defaultFocusedButton === CANCEL_BUTTON) { + if (defaultFocusedButton === CANCEL_BUTTON && this.cancelButton) { this.cancelButton.focus(); - } else if (defaultFocusedButton === CONFIRM_BUTTON) { + } else if (defaultFocusedButton === CONFIRM_BUTTON && this.confirmButton) { this.confirmButton.focus(); } });