Usage
TabContext(...)
TabContext.shinyInput(inputId, ..., value = defaultValue)
updateTabContext.shinyInput(
session = shiny::getDefaultReactiveDomain(),
inputId,
...
)
TabContext.static(..., value = NULL, defaultValue = NULL)Arguments
- ...
Child elements (typically a
BoxwrappingTabList.staticandTabPanelcomponents).valueanddefaultValueare accepted by name only – putting...first guarantees that an unnamed child element is never matched positionally intovalue/defaultValue.- inputId
ID of the component.
- value
Controlled selected tab value. When supplied, the caller is the source of truth: the value is honored on every render and the wrapper never mutates it. Combine with an
onChange(onTabList.staticor onTabContext.static) that writes the new value back to wherever it lives. The tidiest binding needs no JavaScript: make the tab a URL path segment, link eachTabwithhref(e.g."#/overview"), and read it back withreactRouter::useParams(as = "value", selector = "tab"). UseuseParams(a scalar), notuseSearchParams, which returnsgetAll(), an array that never matches aTabPanel's string value. Other sources (a parent's state, a Shiny input) work too. Use eithervalueordefaultValue, not both; the mode is fixed at the first render.- session
Object passed as the `session` argument to Shiny server.
- defaultValue
Uncontrolled initial selected tab value. The wrapper owns the active-tab state and updates it on user clicks. This is the right choice for Quarto documents and static HTML, where no external state is involved.
Details
value
number| string
Default is NA The value of the currently selected Tab.children
node
Default is NA The content of the component.
Note
TabContext is part of @mui/lab,
which is published on the MUI beta channel. Lab APIs may change in future minor
releases.
Pass an initial value matching one of the TabPanel values
to pre-select that panel; when omitted, the component mounts with no panel
selected (value = "") rather than uncontrolled, so a later
server-driven update does not trigger MUI's controlled/uncontrolled warning.
TabContext itself has no change event, so input[[inputId]]
reports only this initial value. To react to tab clicks on the server, read
input[[inputId]] from the TabList.shinyInput instead.
