Content that stays fixed to the top or bottom of the viewport once scrolled to it.
Usage
el_affix(
...,
id = NULL,
offset = NULL,
position = NULL,
target = NULL,
z_index = NULL,
teleported = NULL,
append_to = NULL,
width = NULL,
slots = NULL,
events = NULL,
on = NULL
)
update_el_affix(
session = shiny::getDefaultReactiveDomain(),
id,
offset = NULL,
position = NULL,
z_index = NULL,
target = NULL,
teleported = NULL,
append_to = NULL
)Arguments
- ...
Its content: any Shiny UI. Components of this package are folded into this one's Vue instance, as
el_button_group()folds its buttons.- id
Component ID. Auto-generated if
NULL.- offset
Offset distance. Element Plus's
offset(number).- position
Position of affix. Element Plus's
position('top' | 'bottom').- target
Target container (CSS selector). Element Plus's
target(string).- z_index
z-indexof affix. Element Plus'sz-index(number).- teleported
Whether affix element is teleported, if
trueit will be teleported to whereappend-tosets. Element Plus'steleported(boolean).- append_to
Which element the affix element appends to. Element Plus's
append-to(CSSSelector / HTMLElement).- width
Component width, as a CSS unit.
- slots
Named list of Element slot contents. A scoped slot is written with
template().- 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>_change | unasked | triggers when fixed state changed |
input$<id>_scroll | events = "scroll" | list(scrollTop, fixed), at most every 200 ms |
The same list as el_events("el_affix"), which says how an event's arguments travel.
Updating from the server
update_el_affix() changes the component from the server: every argument of
el_affix() 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_affix() is called for its side effect and returns NULL invisibly.
Examples
el_affix(el_button("top", "Stays on top"), offset = 120)
#> <div id="el_affix_3c766587-e6a7-4f39-b0bd-5e27ab2fde30" data-shiny-vue style="display: contents">
#> <script type="text/x-template" data-shiny-vue-template><div id="el_affix_3c766587-e6a7-4f39-b0bd-5e27ab2fde30_container" style="display: contents">
#> <el-affix v-bind="$optional('affix')" @change="svEmitChange">
#> <el-button v-bind="$optional('button')" :circle="circle" :loading="loading" :disabled="disabled" :native-type="native_type" @click="handleClick" ref="sv_top" id="top">{{label}}</el-button>
#> </el-affix>
#> </div></script>
#> <script type="application/json" data-shiny-vue-options>{"options":{"data":{"offset":120,"position":null,"target":null,"zIndex":null,"teleported":null,"appendTo":null,"label":"Stays on top","circle":false,"loading":false,"disabled":false,"native_type":"button","count":0,"state":"ready","size":null,"icon":null,"autofocus":false,"type":null,"plain":null,"round":null,"autoInsertSpace":null,"bg":null,"color":null,"dark":null,"dashed":null,"link":null,"loadingIcon":null,"tag":null,"text":null},"methods":{"svEmitChange":"function() { window.shinyVue.emit('el_affix_3c766587-e6a7-4f39-b0bd-5e27ab2fde30', 'change', arguments); }","handleClick":"function() { if (this.disabled || this.loading || this.state === 'busy') return; this.count++; window.Shiny && Shiny.setInputValue && Shiny.setInputValue('top:shiny.action', this.count); }"},"mounted":"function() { var self = this; var send = function() { window.Shiny && Shiny.setInputValue && Shiny.setInputValue(\"top:shiny.action\", self.count); }; if (window.Shiny && Shiny.shinyapp && typeof Shiny.shinyapp.isConnected === 'function' && Shiny.shinyapp.isConnected()) { send(); } else if (window.jQuery) { jQuery(document).one('shiny:connected', send); } var prev = self._svReport; self._svReport = function() { if (prev) prev(); self.$nextTick(send); }; }"},"input":null,"rate":null,"type":null,"use":["shinyElement.plugin"],"optional":{"affix":{"offset":"offset","position":"position","target":"target","z-index":"zIndex","teleported":"teleported","append-to":"appendTo"},"button":{"size":"size","icon":"icon","autofocus":"autofocus","type":"type","plain":"plain","round":"round","auto-insert-space":"autoInsertSpace","bg":"bg","color":"color","dark":"dark","dashed":"dashed","link":"link","loading-icon":"loadingIcon","tag":"tag","text":"text"}},"absorbed":{"top":{"fields":{"label":"label","circle":"circle","loading":"loading","disabled":"disabled","native_type":"native_type","count":"count","state":"state","size":"size","icon":"icon","autofocus":"autofocus","type":"type","plain":"plain","round":"round","autoInsertSpace":"autoInsertSpace","bg":"bg","color":"color","dark":"dark","dashed":"dashed","link":"link","loadingIcon":"loadingIcon","tag":"tag","text":"text","handleClick":"handleClick"},"ref":"sv_top"}},"generated":true,"evals":["options.methods.svEmitChange","options.methods.handleClick","options.mounted"]}</script>
#> </div>