Skip to content

Commit

Permalink
fix(SharePopover): restore focus on close (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
PahaN47 authored Sep 12, 2024
1 parent 092657c commit 4cd524e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/SharePopover/SharePopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const SharePopover = (props: SharePopoverProps) => {
buttonAriaLabel,
} = props;
const [isOpen, setIsOpen] = React.useState(false);
const buttonRef = React.useRef<HTMLButtonElement>(null);
const tooltipId = useUniqId();

const content = React.useMemo(
Expand Down Expand Up @@ -174,6 +175,7 @@ export const SharePopover = (props: SharePopoverProps) => {
onOpenChange={setIsOpen}
focusTrap={!shouldOpenByHover}
autoFocus={!shouldOpenByHover}
restoreFocusRef={shouldOpenByHover ? undefined : buttonRef}
>
{({onClick: onClickInner}) => (
<button
Expand All @@ -183,6 +185,7 @@ export const SharePopover = (props: SharePopoverProps) => {
aria-describedby={tooltipId}
aria-label={buttonAriaLabel}
onClick={onClickInner}
ref={buttonRef}
>
<div className={b('icon-container')}>
<Icon
Expand Down

0 comments on commit 4cd524e

Please sign in to comment.