Links to sections of the page, the one in view marked as the page scrolls.
Usage
el_anchor(
id = NULL,
links = list(),
container = NULL,
offset = NULL,
bound = NULL,
duration = NULL,
marker = NULL,
type = NULL,
direction = NULL,
select_scroll_top = NULL,
width = NULL,
slots = NULL,
events = NULL,
on = NULL
)
update_el_anchor(
session = shiny::getDefaultReactiveDomain(),
id,
offset = NULL,
bound = NULL,
duration = NULL,
marker = NULL,
type = NULL,
direction = NULL,
select_scroll_top = NULL,
container = NULL
)Arguments
- id
Anchor ID. Auto-generated if
NULL.- links
The links, each an
el_anchor_link()– or alist(title =, href = "#section"), each with optionalchildren, a list of links one level down.- container
A CSS selector for the element that scrolls, when it is not the page.
- offset
Offset of the scroll position, in pixels.
- bound
Distance from the top at which a section counts as reached, in pixels. Default
15.- duration
Duration of the scroll, in milliseconds. Default
300.- marker
Whether to show the marker beside the current link.
- type
"default"or"underline".- direction
"vertical"(the default) or"horizontal".- select_scroll_top
Whether a link counts as current once its section is scrolled to the top.
- width
Component width, as a CSS unit.
- slots
Named list of Element slot contents.
- events
Element's events to report besides those reported unasked, by name:
events = "node_drop"reportsinput$<id>_node_drop. The component's are listed under "Shiny inputs", and byel_events(); a name it does not have is an error.- on
Handlers of your own, for an event not reported or to send something else: a named list of
JS()functions, one per event – Element's, or a DOM event with Vue's modifiers ("keyup.enter"). Each is called withreportand the event's arguments;report(name, value)setsinput$<id>_<name>. Seeel_widget().- session
Shiny session; the current one by default, as for
shiny::updateTextInput().
Shiny inputs
| Input | Reported | Value |
input$<id> | unasked | the href of the current link, as the page scrolls |
input$<id>_click | events = "click" | the href of the link clicked |
The same list as el_events("el_anchor"), which says how an event's arguments travel.
Element methods
Callable with call_el(): scrollTo(href).
Binding
Every argument can follow v_bind() or v_model() except links (the links, drawn by R); width (the mount point's style).
Updating from the server
update_el_anchor() changes the component from the server: every argument of
el_anchor() that can change once it is drawn, under the same name. One left
NULL stays as it is; NA returns it to Element's default.
update_el_anchor() is called for its side effect and returns NULL invisibly.
Examples
el_anchor(
"toc",
links = list(
list(title = "Basic usage", href = "#basic"),
list(
title = "API",
href = "#api",
children = list(
list(title = "Attributes", href = "#attributes")
)
)
)
)
#> <div id="toc" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><div id="toc_container" style="display: contents">
#> <el-anchor v-bind="$optional('anchor')" @change="handleChange">
#> <el-anchor-link title="Basic usage" href="#basic"></el-anchor-link>
#> <el-anchor-link title="API" href="#api">
#> <template v-slot:sub-link>
#> <el-anchor-link title="Attributes" href="#attributes"></el-anchor-link>
#> </template>
#> </el-anchor-link>
#> </el-anchor>
#> </div></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"container":null,"offset":null,"bound":null,"duration":null,"marker":null,"type":null,"direction":null,"selectScrollTop":null},"methods":{"handleChange":"function(href) { window.Shiny && Shiny.setInputValue && Shiny.setInputValue('toc', href); }"}},"input":null,"rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"anchor":{"container":"container","offset":"offset","bound":"bound","duration":"duration","marker":"marker","type":"type","direction":"direction","select-scroll-top":"selectScrollTop"}},"evals":["options.methods.handleChange"]}</script>
#> </div>