feat(offcanvas): show_offcanvas() accepts a character id - #1346
Merged
Conversation
show_offcanvas() previously only accepted a bslib_offcanvas object,
silently coercing any other input (including a bare string) into body
content for a new anonymous panel. This made it inconsistent with
hide_offcanvas()/toggle_offcanvas(), which are id-oriented, and meant
show_offcanvas("panel") did not do what users expected.
Closes #1345
Adds test cases for the new character-id branch and confirms the list/tagList anonymous-panel path still works. Regenerates man/show_offcanvas.Rd and documents the behavior change in NEWS.md.
…() id path htmltools::HTML() is a character vector under the hood, so it needs an explicit exclusion to route to the body-content path instead of being treated as an id. Strings containing whitespace or empty strings can't be valid HTML ids, so treat those as likely-mistaken body text and error with actionable guidance instead of silently misinterpreting them.
Cite the PR number per convention and note the HTML()/whitespace error behavior added since the note was first drafted.
gadenbuie
marked this pull request as ready for review
August 13, 2026 13:23
cpsievert
approved these changes
Aug 13, 2026
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1345
Summary
show_offcanvas()previously only accepted abslib_offcanvasobject. Any other input, including a bare string, was silently coerced into body content for a new anonymous panel, unlike its id-oriented siblingshide_offcanvas()/toggle_offcanvas(). This madeshow_offcanvas("panel")do the wrong thing instead of revealing the existing panel.show_offcanvas()now dispatches on the type of its first argument:character(1)-> theidof a panel already in the UI (reveals it)htmltools::HTML(),tagList()) -> wrapped into a new anonymous panel (today's old behavior, minus bare characters)bslib_offcanvasobject -> rendered + shown (unchanged)Since a plain character string containing whitespace or being empty cannot be a valid HTML id, and is almost certainly mistaken body text,
show_offcanvas()now errors with actionable guidance in that case rather than silently misinterpreting it.htmltools::HTML()is explicitly excluded from the id path (it is a character vector under the hood) so it is still treated as body content.No client-side (
srcts/) changes were needed: showing an existing panel by id sends the same{method: "toggle", value: "show"}messagetoggle_offcanvas(id, show = TRUE)already sends.Reproducible Shiny app
The first button is the behavior introduced by this PR: it opens the predeclared
existing-panelby id. The other two confirm thathtmltools::HTML()continues to be body content and that passing anoffcanvas()object is unchanged.Breaking change
show_offcanvas("some string")used to create a new anonymous panel with that string as its body. It is now treated as anidlookup instead, and errors if the string looks like body text (contains whitespace, or is empty). This is a behavior change to a function released in bslib 0.12.0.