Expand commentComment on line R9Resolved

Popover

The popover component shows contextual content anchored to an element. It is used to present additional information or actions without disrupting the interface.

Props

NameTypeDescriptionDefault
actionToOpen'click' | 'hover'Action that triggers the popover to open.'click'
align'start' | 'center' | 'end'Alignment of the popover relative to the trigger element.'center'
asChildbooleanSet to true if child controls the events. It will render the child directly without wrapping it.-
Required
children
React.ReactNodeElement that triggers the popover and works as the anchor.-
hasTipbooleanWhether the popover should display a tip (arrow).false
isOpenbooleanControlled open state of the popover. If it is left undefined, it will be uncontrolled.-
offsetnumberDistance in pixels from the trigger element to the popover.4
onClose() => voidCallback function when the popover is opened. Used only in controlled mode and if the trigger lacks the events to manage the controlled behavior.-
onOpen() => voidCallback function when the popover is closed.-
Required
popoverContent
React.ReactNodeContent to be displayed inside the popover.-
side'top' | 'bottom' | 'left' | 'right'Side of the trigger where the popover will appear.'bottom'

Examples

Uncontrolled Popover

() => {
  return (
    <DxcContainer height="100px" padding="var(--spacing-padding-m)" boxSizing="border-box">
        <DxcPopover
        actionToOpen="hover"
        popoverContent={<DxcParagraph>Popover content.</DxcParagraph>}>
            <DxcParagraph>Hover me to see the popover.</DxcParagraph>
        </DxcPopover>
    </DxcContainer>
  );
}

Controlled Popover

() => {
const [isOpen, setIsOpen] = useState(false);
  return (
    <DxcContainer height="100px" padding="var(--spacing-padding-m)" boxSizing="border-box">
      <DxcPopover
        isOpen={isOpen}
        onOpen={() => setIsOpen(true)}
        onClose={() => setIsOpen(false)}
        popoverContent={<DxcParagraph>Popover content.</DxcParagraph>}
      >
        <DxcParagraph>Click me to see the popover.</DxcParagraph>
      </DxcPopover>
    </DxcContainer>
  );
}