Skip to content

Commit

Permalink
fix(Alert): forward ref to the alert dom element (#5010)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamandrewluca committed Feb 28, 2020
1 parent f4dde13 commit fb79f2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const Alert = React.forwardRef((uncontrolledProps, ref) => {
<div
role="alert"
{...(Transition ? props : undefined)}
ref={ref}
className={classNames(
className,
prefix,
Expand All @@ -102,7 +103,7 @@ const Alert = React.forwardRef((uncontrolledProps, ref) => {
if (!Transition) return show ? alert : null;

return (
<Transition unmountOnExit ref={ref} {...props} in={show}>
<Transition unmountOnExit {...props} in={show}>
{alert}
</Transition>
);
Expand Down
6 changes: 6 additions & 0 deletions test/AlertSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('<Alert>', () => {
);
});

it('should forward refs to the alert', () => {
const ref = React.createRef();
mount(<Alert ref={ref}>Yo</Alert>);
ref.current.tagName.should.equal('DIV');
});

describe('Web Accessibility', () => {
it('Should have alert role', () => {
mount(<Alert>Message</Alert>).assertSingle('[role="alert"]');
Expand Down

0 comments on commit fb79f2a

Please sign in to comment.