Skip to content

Commit

Permalink
feat(Popover): add ariaLabel prop
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkaaa committed Dec 6, 2024
1 parent 221a67f commit d7f4f50
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/orbit-components/src/Popover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The table below contains all types of props available in the Popover component.
| labelClose | `React.Node` | `Close` | The label for close button. |
| renderTimeout | `number` | `0` | The timeout for rendering the Popover. |
| zIndex | `number` | `710` | The zIndex value of the Popover component. |
| ariaLabel | `string` | | Optional prop for `aria-label` value (accessibility). |

## enum

Expand Down Expand Up @@ -110,3 +111,7 @@ The table below contains all types of props available in the Popover component.
<Button>Open Popover</Button>
</Popover>
```

## Accessibility

- The `ariaLabel` prop allows you to specify an `aria-label` attribute for the popover content component. This attribute provides additional information to screen readers, enhancing the accessibility of the component. By using `ariaLabel`, you can ensure that users who rely on assistive technologies receive the necessary context and information about the component's purpose and functionality.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface Props extends Common.Globals {
actions?: React.ReactNode;
offset?: Offset;
onClose: (ev?: MouseEvent | React.SyntheticEvent<HTMLElement>) => void;
ariaLabel?: string;
}

const PopoverContentWrapper = ({
Expand All @@ -67,6 +68,7 @@ const PopoverContentWrapper = ({
allowOverflow,
lockScrolling = true,
actions,
ariaLabel,
}: Props) => {
const [actionsHeight, setActionsHeight] = React.useState<number | null>(null);
const { isInsideModal } = React.useContext(ModalContext);
Expand Down Expand Up @@ -198,6 +200,7 @@ const PopoverContentWrapper = ({
shown ? "lm:opacity-100" : "lm:opacity-0",
)}
style={cssVars}
aria-label={ariaLabel}
>
<div
ref={content}
Expand Down
2 changes: 2 additions & 0 deletions packages/orbit-components/src/Popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Popover = ({
actions,
overlapped,
dataTest,
ariaLabel,
}: Props) => {
const ref = React.useRef<HTMLDivElement | null>(null);
const popoverId = useRandomId();
Expand Down Expand Up @@ -142,6 +143,7 @@ const Popover = ({
referenceElement={ref.current}
onClose={handleOut}
placement={placement}
ariaLabel={ariaLabel}
>
{content}
</PopoverContent>
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/src/Popover/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export interface Props extends Common.Globals {
readonly renderInPortal?: boolean;
readonly onClose?: Common.Callback;
readonly zIndex?: number;
readonly ariaLabel?: string;
}

0 comments on commit d7f4f50

Please sign in to comment.