Repository navigation
Description
It's currently difficult to add page-level attributes, and our page functions provide an inconsistent API. Supposing I'd like to add the foo class to the <body> element, only page() and page_fillable() give the desired results.
| Function Call | Result |
|---|---|
page(class = "foo") |
.foo is added to the <body> |
page_fillable(class = "foo") |
.foo is added to the <body> |
page_navbar(class = "foo") |
Errors |
page_sidebar(class = "foo") |
.foo is added to the .main content area of the sidebar layout (passes class to layout_sidebar()) |
page_fluid(class = "foo") |
Returns a div.container-fluid.foo, not a body tag |
page_fixed(class = "foo") |
Returns a div.container.foo element, not a body tag |
There are two key challenges in resolving this problem:
- We can upgrade
page_fluid()andpage_fixed()to usebslib::page()but for backwards compatibility, the...elements should be handed todiv(class = "container, ...). - We can't redirect the
...inpage_sidebar()andpage_navbar()without breaking behavior since they're used bylayout_sidebar()and the navset generator function.
Proposal
We add an argument that collects page-level attributes to each of the above functions, named something like page_attrs or .attributes. This argument would take a list – created with list() or a helper like page_attributes() – and would apply the attributes to the page element.
In page_fillable() and page(), where the ... are already passed to the tags$body(), we'd fold this list into that call. In page_fluid() and page_fixed() we'd pass the page_attrs to the page() function and continue to pass the ... to the container div.
page(page_attrs = list(class = "foo"))
page_fillable(page_attrs = list(class = "foo"))
page_navbar(page_attrs = list(class = "foo"))
page_sidebar(page_attrs = list(class = "foo"))
page_fluid(page_attrs = list(class = "foo"))
page_fixed(page_attrs = list(class = "foo"))A more automagical approach would be to allow page_attributes() to be included unnamed in the ... of the above functions. The page functions could inspect the ..., pull out the page attributes object and apply the attributes appropriately to the body tag.
page(page_attributes(class = "foo"))
page_fillable(page_attributes(class = "foo"))
page_navbar(page_attributes(class = "foo"))
page_sidebar(page_attributes(class = "foo"))
page_fluid(page_attributes(class = "foo"))
page_fixed(page_attributes(class = "foo"))
Activity
cpsievert commentedon Nov 8, 2023
Oh interesting. I kind of like the idea of
page_attributes(), which could be implemented as a web components that add/removes attributes on thedocument.bodyduringconnectedCallback()/disconnectedCallback()?