Unverified Commit a18fd5d7 by Michael Roytman Committed by GitHub

fix(statusalert): Expose focus function on StatusAlert component

fix(statusalert): Expose focus function on StatusAlert component
parents 805e888d b783247b
...@@ -2,6 +2,7 @@ import React from 'react'; ...@@ -2,6 +2,7 @@ import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import StatusAlert from './index'; import StatusAlert from './index';
import Button from '../Button';
const statusAlertOpen = (isOpen, wrapper) => { const statusAlertOpen = (isOpen, wrapper) => {
expect(wrapper.childAt(0).hasClass('show')).toEqual(isOpen); expect(wrapper.childAt(0).hasClass('show')).toEqual(isOpen);
...@@ -114,4 +115,22 @@ describe('<StatusAlert />', () => { ...@@ -114,4 +115,22 @@ describe('<StatusAlert />', () => {
statusAlertOpen(true, wrapper); statusAlertOpen(true, wrapper);
}); });
}); });
describe('focus functions properly', () => {
it('focus function changes focus', () => {
wrapper = mount(<div>
<Button label="test" />
<StatusAlert {...defaultProps} />
</div>);
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);
});
});
}); });
...@@ -37,6 +37,10 @@ class StatusAlert extends React.Component { ...@@ -37,6 +37,10 @@ class StatusAlert extends React.Component {
} }
} }
focus() {
this.xButton.focus();
}
close() { close() {
this.setState({ open: false }); this.setState({ open: false });
this.props.onClose(); this.props.onClose();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment