diff --git a/src/StatusAlert/StatusAlert.test.jsx b/src/StatusAlert/StatusAlert.test.jsx index d9eaa02884..8c285a76d7 100644 --- a/src/StatusAlert/StatusAlert.test.jsx +++ b/src/StatusAlert/StatusAlert.test.jsx @@ -2,6 +2,7 @@ import React from 'react'; import { mount } from 'enzyme'; import StatusAlert from './index'; +import Button from '../Button'; const statusAlertOpen = (isOpen, wrapper) => { expect(wrapper.childAt(0).hasClass('show')).toEqual(isOpen); @@ -114,4 +115,22 @@ describe('', () => { statusAlertOpen(true, wrapper); }); }); + describe('focus functions properly', () => { + it('focus function changes focus', () => { + wrapper = mount(
+
); + + const buttons = wrapper.find('button'); + + // move focus away from default StatusAlert xButton + buttons.at(0).simulate('click'); + expect(buttons.at(0).html()).toEqual(document.activeElement.outerHTML); + + const statusAlert = wrapper.find('StatusAlert').instance(); + statusAlert.focus(); + expect(buttons.at(1).html()).toEqual(document.activeElement.outerHTML); + }); + }); }); diff --git a/src/StatusAlert/index.jsx b/src/StatusAlert/index.jsx index 11242b4642..d0787e5b30 100644 --- a/src/StatusAlert/index.jsx +++ b/src/StatusAlert/index.jsx @@ -37,6 +37,10 @@ class StatusAlert extends React.Component { } } + focus() { + this.xButton.focus(); + } + close() { this.setState({ open: false }); this.props.onClose();