Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
fix(Status): Pass refs to Status element
Browse files Browse the repository at this point in the history
  • Loading branch information
diondiondion committed Jun 10, 2020
1 parent 10333d6 commit 10f6b18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Status/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ For more control you can override each of these props.
const [showConfirmation, setShowConfirmation] = React.useState(false);
return (
<>
<Button onClick={() => setShowConfirmation(v => !v)}>
<Button
isActive={showConfirmation}
onClick={() => setShowConfirmation(v => !v)}
>
Click me
</Button>
<Status>
Expand All @@ -41,11 +44,11 @@ For more control you can override each of these props.

Make sure that the `Status` component is always rendered – even when it's empty – before you update its contents. If the element is added alongside its content, screen readers will **not** announce it!

The above example would break if it was written like below:
The example below would not work:

```jsx
{
showConfirmation && <Status>Congrats, you have clicked the button!</Status>;
showConfirmation && <Status>This status will NOT BE announced :(</Status>;
}
```
Expand Down
9 changes: 6 additions & 3 deletions src/Status/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React from 'react';
import React, {forwardRef} from 'react';
import PropTypes from 'prop-types';

import Box from '../Box';

function Status(props) {
const Status = forwardRef((props, ref) => {
return (
<Box
ref={ref}
role="status"
aria-live="polite"
aria-relevant="additions text"
{...props}
aria-atomic={props.atomic ? 'true' : props['aria-atomic']}
/>
);
}
});

Status.displayName = 'Status';

Status.propTypes = {
atomic: PropTypes.bool,
Expand Down

0 comments on commit 10f6b18

Please sign in to comment.