1.23.0 • Published 7 months ago

@asphalt-react/popover v1.23.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
7 months ago

Popover

Popover provides containers to create overlays like tooltips, calenders etc. It represents the UI element as floating above the normal flow creating the "pop out" effect. Popover can contain a range of elements from simple strings to complex React designs.

Popover requires a target element which acts as a pivot for the content. Popover supports multiple placement positions using which <Popover/> element can be positioned next to the target element in any direction.

Note: React ref should be forwarded to the underlying element, in case the target is a React component.

Usage

import React from "react"
import Popover from "@asphalt-react/popover"

const App = () => (
  <Popover target={<Button>Click Me<Button/>}>
    <p
      style={{
        width: "400px",
        backgroundColor: "#fff",
        padding: "1rem",
        margin: 0
      }}
    >
        Hello there!!
    </p>
  </Popover>
)

export default App

Accessibility

  • Pressing Esc key or clicking anywhere outside the popover closes it.
  • Popover traps focus within its content, rotating the focus among its interactive elements.
  • The first interactive element receives focus when Popover opens (unless smartFocus is set to false)

Props

children

React node to render inside Popover

typerequireddefault
nodetrueN/A

target

Target node that triggers the Popover

typerequireddefault
elementtrueN/A

placement

Placement of the Popover with respect to target node

Popover supports multiple placements:

  • autoauto-startauto-end
  • toptop-starttop-end
  • bottombottom-startbottom-end
  • leftleft-startleft-end
  • rightright-startright-end
typerequireddefault
enumfalse"bottom"

smartFocus

Adds focus to first interactive element when Popover is visible. It's enabled by default for better accessibility

from v1.3.0+

typerequireddefault
boolfalsetrue

skipBounds

When Popover is added to a container with position: fixed and/or overflow: hidden, it creates a containing block with a stacking context which the Popover can't skip. In such senarios, enabling skipBounds will force Popover to skip its parent's boundaries.

from v1.3.0+

typerequireddefault
boolfalsefalse

onOpen

Callback to notify that Popover is open. The callback has the argument of the shape:

{
  event: React synthetic event
}
typerequireddefault
funcfalseN/A

onClose

Callback to notify that Popover is close. The callback has the argument of the shape:

{
  event: React synthetic event
}
typerequireddefault
funcfalseN/A