Skip to content

Commit

Permalink
feat(Popover): prevent closing by click in case of using openOnHover …
Browse files Browse the repository at this point in the history
…property (#1085)
  • Loading branch information
korvin89 authored Nov 3, 2023
1 parent 55885d0 commit 2c17a06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const Popover = React.forwardRef<PopoverInstanceProps, PopoverProps & QAP
closeTooltip={closeTooltip}
openTooltip={openTooltip}
open={isOpen}
openOnHover={openOnHover}
className={cnPopover('handler')}
disabled={disabled}
onClick={onClick}
Expand Down
8 changes: 7 additions & 1 deletion src/components/Popover/components/Trigger/Trigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface TriggerProps {
* Tooltip's opened state
*/
open: boolean;
openOnHover?: boolean;
/**
* Css class for the control
*/
Expand Down Expand Up @@ -44,6 +45,7 @@ export interface TriggerProps {

export const Trigger = ({
open,
openOnHover,
disabled,
className,
openTooltip,
Expand All @@ -53,7 +55,11 @@ export const Trigger = ({
children,
}: TriggerProps) => {
const handleClick = async (event: React.MouseEvent<HTMLDivElement>) => {
if (disabled) {
// Ignores click that should close tooltip in case of {openOnHover: true}
// to prevent situation when user could close tooltip accidentally
const shouldPreventClosingByClick = open && openOnHover;

if (disabled || shouldPreventClosingByClick) {
return;
}

Expand Down

0 comments on commit 2c17a06

Please sign in to comment.