Skip to contents

[Experimental] Wraps the words of a tip's long form with the moment it shows, to give as more to tip_on() or tip_spec(). With no tip_more(), more = "words" is the same as more = tip_more("words"): the tip is short, and a "More" button in it opens the long form.

Usage

tip_more(
  content,
  ...,
  on = NULL,
  label = NULL,
  pin = FALSE,
  as = NULL,
  where = NULL
)

Arguments

content

The words of the long form (markdown, with {{ field }} placeholders filled from the tip's record or, in a table, from the row), or a tip_template(). NA and "" mean no long form.

...

Must be empty. It makes a misspelt argument an error.

on

When the long form shows: "button" (a "More" button opens it), "hover" (at once), "pin" (when the tip is pinned) or "click" (a click on the item opens it, with no button). NULL, the default, is "button". "click" is not for a table, where a click selects a row.

label

The words of the buttons, only with "button": one string for the "More" button (the "Less" button keeps its word), or c(more = "Show all", less = "Show less"). NULL gives the built-in "More" and "Less". With "hover", "pin" or "click" there is no button, so a label is an error. It beats the more and less words of labels (see tip_on() and use_hovercraft()) for this tip.

pin

TRUE makes the "More" button (and the M key) pin the tip as well as open its long form, so the long form stays. FALSE, the default, never pins. Only with "button", and only on a tip that can pin: tip_on() with pin = TRUE and an id, or a row of tip_table() with tip_spec(pin = TRUE).

as

How the control looks: "button" (a small button) or "link" (an italic text link). NULL, the default, is "button". Only with on = "button"; with another moment there is no control, so it is an error.

where

Which side of the bottom of the tip the control sits on: "end" or "start", in the reading direction. NULL, the default, puts a button at the end and a link at the start. Only with on = "button".

Value

An object of class hovercraft_more, to give as more to tip_on() or tip_spec().

Details

With on = "button" (the default) a "More" button at the bottom of the short tip opens the long form in the same tip, and a "Less" button closes it again. It does not pin (unless pin = TRUE, below), and needs no tip pin and no id. The tip is short again the next time it opens. A pinned tip gets the same buttons. The M key opens and closes the long form while the keyboard focus is on the tagged item or the pointer rests on it, except while the focus is in a text field, where a letter is a letter. When the focus is on one item and the pointer rests on another, the key acts on the item under the pointer, the tip the reader sees, not on one around it; a pinned tip that holds the focus keeps the key. A tip that a tap or tip_show() opened does not take the key from the pointer. It is a letter key that works from a hover, so a page switches it off for every reader with use_hovercraft(keys = c(more = FALSE)); there is no switch for one reader. A tag with a long form announces the key as aria-keyshortcuts. The tip stays open and on its side when it grows or shrinks, grows away from its item and scrolls when there is no more room, instead of flipping to the other side; that is the engine's own behaviour (0.58.0).

as and where choose the look and the place of the control that opens the long form (only with on = "button"). as = "button" (the default) is the small button in the bottom corner of the tip, at its end; as = "link" is an italic, underlined text link at the bottom of the tip, at its start. where says the side, "end" or "start", and follows the reading direction, so the end is the right in English and the left in Arabic. Both are the same control to a keyboard and a screen reader: the link is a real <button> styled as a link, which says "button" and "expanded" or "collapsed" to a screen reader, takes Enter and Space, and does not navigate; an <a> would need role = "button" and its own key handling to do the same. It is a tab stop in a pinned tip, M and aria-keyshortcuts work as for the button, and the words are still the ones of label and labels.

With on = "click" a click on the tagged item opens and closes the long form, and the tip has no button. The item should take keyboard focus (tabindex = "0" on a <span> or <div>), because the M key is the keyboard route: it does the same, and the item announces it as aria-keyshortcuts. The long form is announced to a screen reader when it opens; the item gets no aria-expanded and no role, since a click on a plain tag is not a control. The tip must be open: a click that opens the tip (a first tap on a touch screen) only opens it, short, and the next click opens or closes the long form (on a touch screen the engine closes the tip on a second tap, so use the default button there). The click never pins, so pin = "click" with it is an error. A control, or a tag that holds one (a button, an input, a link, a label ...), is refused, because a click on it has its own job, and so is a table: a click on a row selects it. Use the default button there.

With pin = TRUE the "More" button, and the M key, also pin the tip, so the long form stays; "Less" then only closes the long form and the tip stays pinned. It needs a tip that can pin, the same as on = "pin". Today's default, pin = FALSE, never pins: a pinned tip stays pinned when it opens its long form.

With on = "hover" the long form shows at once, with the short one. With on = "pin" it shows when the tip is pinned, so the tip must be able to pin: tip_on(pin = TRUE) with an id, or a row of tip_table() with tip_spec(pin = TRUE); without a pin it is an error.

A tip that expands sends no Shiny input. A pinned tip drawn again, such as one that opens its long form, sends input$<id>_pin with state = "updated"; the values of state may grow in a later version, so an app should not assume it knows them all.

Examples

tip_on(
  htmltools::tags$button("Run"),
  "Runs the checks.",
  more = tip_more("Takes about a minute on the full data.")
)
#> <button data-hovercraft-tip="Runs the checks." data-hovercraft-more-held="Takes about a minute on the full data." aria-keyshortcuts="M">Run</button>

# A click on the item opens the long form, and the More button pins the tip
tip_on(
  htmltools::tags$span("Run", tabindex = "0"),
  "Runs the checks.",
  more = tip_more("Takes about a minute.", on = "click")
)
#> <span tabindex="0" data-hovercraft-tip="Runs the checks." data-hovercraft-more-held="Takes about a minute." data-hovercraft-more-click="true" aria-keyshortcuts="M">Run</span>
tip_on(
  htmltools::tags$button("Run", id = "run"),
  "Runs the checks.",
  id = "run_tip",
  pin = TRUE,
  more = tip_more("Takes about a minute.", pin = TRUE)
)
#> <button id="run" data-hovercraft-tip="Runs the checks." data-hovercraft-tip-id="run_tip" data-hovercraft-tip-pin="manual" data-hovercraft-more-held="Takes about a minute." data-hovercraft-more-pin="true" aria-keyshortcuts="P M">Run</button>

# A text link at the start of the bottom of the tip, instead of the button
tip_on(
  htmltools::tags$button("Run"),
  "Runs the checks.",
  more = tip_more("Takes about a minute.", as = "link")
)
#> <button data-hovercraft-tip="Runs the checks." data-hovercraft-more-held="Takes about a minute." data-hovercraft-more-as="link" aria-keyshortcuts="M">Run</button>

# The long form shows with the short one, and the buttons say other words
tip_on(
  htmltools::tags$button("Run"),
  "Runs the checks.",
  more = tip_more("Takes about a minute.", on = "hover")
)
#> <button data-hovercraft-tip="Runs the checks." data-hovercraft-tip-more="Takes about a minute." data-hovercraft-tip-more-on="hover">Run</button>
tip_on(
  htmltools::tags$button("Run"),
  "Runs the checks.",
  more = tip_more("Takes about a minute.", label = c(more = "Details", less = "Fewer details"))
)
#> <button data-hovercraft-tip="Runs the checks." data-hovercraft-more-held="Takes about a minute." data-hovercraft-more-label="{&quot;more&quot;:&quot;Details&quot;,&quot;less&quot;:&quot;Fewer details&quot;}" aria-keyshortcuts="M">Run</button>