NoRedInk/noredink-ui/16.5.0

NOTE: the latest version is 35.9.3

Nri.Ui.Tooltip.V3

Changes from V2:

  • Support disclosure pattern for rich-content tooltips
  • render tooltip content in the DOM when closed (now, they're hidden with display:none)
  • tooltips MUST be closable via keyboard without moving focus. Understanding Success Criterion 1.4.13: Content on Hover or Focus
  • remove onClick helper
  • prefer the accessible name to using aria-labelledby and aria-label together
  • :skull: remove customTooltipAttributes
  • change css to extend the current list of styles, NOT override them entirely.
  • fix spelling of "auxillary" to "auxiliary"
  • toggleTip -> viewToggleTip
  • Adds notMobileCss, mobileCss, quizEngineMobileCss
  • onHover -> onToggle

These tooltips aim to follow the accessibility recommendations from:

{ trigger : List (Attribute msg) -> Html msg
, id : String
}
-> List (Attribute msg)
-> Html msg

Here's what the fields in the configuration record do:

  • trigger: What element do you interact with to open the tooltip?
  • id: A unique identifier used to associate the trigger with its content
{ label : String
, lastId : Maybe String
}
-> List (Attribute msg)
-> Html msg

Supplementary information triggered by a "?" icon.

This is a helper for setting up a commonly-used disclosure tooltip. Please see the documentation for disclosure to learn more.

type Attribute msg
plaintext : String -> Attribute msg
html : List (Html msg) -> Attribute msg

Makes it so that the tooltip does not have a tail!

 __________
|         |
|___  ____|
    \/
 ___/\_____
|         |
|_________|
  __________
 |         |
 |          >
 |_________|
  __________
 |         |
<          |
 |_________|

Set the position of the tooltip when the mobile breakpoint applies.

 __________
|         |
|___  ____|
    \/

Set the position of the tooltip when the mobile breakpoint applies.

 ___/\_____
|         |
|_________|

Set the position of the tooltip when the mobile breakpoint applies.

  __________
 |         |
 |          >
 |_________|

Set the position of the tooltip when the mobile breakpoint applies.

  __________
 |         |
<          |
 |_________|
alignStart : Px -> Attribute msg

Put the tail at the "start" of the tooltip. For onTop & onBottom tooltips, this means "left". For onLeft & onRight tooltip, this means "top".

 __________
|_  ______|
  \/

Put the tail at the "middle" of the tooltip. This is the default behavior.

 __________
|___  ____|
    \/
alignEnd : Px -> Attribute msg

Put the tail at the "end" of the tooltip. For onTop & onBottom tooltips, this means "right". For onLeft & onRight tooltip, this means "bottom".

 __________
|______  _|
       \/

Put the tail at the "start" of the tooltip when the viewport has a mobile width. For onTop & onBottom tooltips, this means "left". For onLeft & onRight tooltip, this means "top".

 __________
|_  ______|
  \/

Put the tail at the "middle" of the tooltip when the viewport has a mobile width. This is the default behavior.

 __________
|___  ____|
    \/

Put the tail at the "end" of the tooltip when the viewport has a mobile width. For onTop & onBottom tooltips, this means "right". For onLeft & onRight tooltip, this means "bottom".

 __________
|______  _|
       \/
exactWidth : Int -> Attribute msg

Define a size in px for the tooltips's total width. The default is 320px.

Tooltip width fits its content.

This the default spacing.

customPadding : Float -> Attribute msg

Pass in the desired spacing around the edge of the tooltip (pixels).

onToggle : (Bool -> msg) -> Attribute msg

The Tooltip event cycle depends on whether you're following the Disclosure pattern, but disguising the Disclosure as a tooltip visually or you're actually adding a hint or label for sighted users.

If you're adding a tooltip to an element that does something on its own, e.g., a "Print" ClickableSvg, then it doesn't make sense for the tooltip to change state on click/enter/space.

However, if you're adding a tooltip to an element that is not interactive at all if you don't count the tooltip, then we can use the click/enter/space events to manage the tooltip state too. This style of "tooltip" is the only kind that will be accessible for touch users on mobile -- it's important to get the access pattern right!

If the tooltip behavior you're seeing doesn't feel quite right, consider whether you need to change tooltip "types" to disclosure or to auxiliaryDescription.

open : Bool -> Attribute msg

Pass a bool indicating whether the tooltip should be open or closed.

css : List Style -> Attribute msg

Set some custom styles on the tooltip.

notMobileCss : List Style -> Attribute msg

Set styles that will only apply if the viewport is wider than NRI's mobile breakpoint.

Equivalent to:

Tooltip.css
    [ Css.Media.withMedia [ Nri.Ui.MediaQuery.V1.notMobile ] styles ]
mobileCss : List Style -> Attribute msg

Set styles that will only apply if the viewport is narrower than NRI's mobile breakpoint.

Equivalent to:

Tooltip.css
    [ Css.Media.withMedia [ Nri.Ui.MediaQuery.V1.mobile ] styles ]
quizEngineMobileCss : List Style -> Attribute msg

Set styles that will only apply if the viewport is narrower than NRI's quiz-engine-specific mobile breakpoint.

Equivalent to:

Tooltip.css
    [ Css.Media.withMedia [ Nri.Ui.MediaQuery.V1.quizEngineMobile ] styles ]
containerCss : List Style -> Attribute msg
custom : List (Attribute Never) -> Attribute msg

Use this helper to add custom attributes.

Do NOT use this helper to add css styles, as they may not be applied the way you want/expect if underlying styles change. Instead, please use the css helper.

nriDescription : String -> Attribute msg
testId : String -> Attribute msg

Used when the content of the tooltip is identical to the accessible name.

For example, when using the Tooltip component with the ClickableSvg component, the Tooltip is providing extra information to sighted users that screenreader users already have.

This is the default.

Used when the content of the tooltip provides an "auxiliary description" for its content.

An auxiliary description is used when the tooltip content provides supplementary information about its trigger content.

{ triggerId : String
, lastId : Maybe String
}
-> Attribute msg

Sometimes a "tooltip" only looks like a tooltip, but is really more about hiding and showing extra information when the user asks for it.

If clicking the "tooltip trigger" only ever shows you more info (and especially if this info is rich or interactable), use this attribute.

For more information, please read Sarah Higley's "Tooltips in the time of WCAG 2.1" post.

You will need to pass in the last focusable element in the disclosed content in order for:

  • any focusable elements in the disclosed content to be keyboard accessible
  • the disclosure to close appropriately when the user tabs past all of the disclosed content

You may pass a lastId of Nothing if there is NO focusable content within the disclosure.