rstudio / rstudio/bslib

Allow setting attributes at the page level, especially`class` and `style`

Open
#899 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
SCSS
Stars
569
Forks
72
Avg merge
1d 2h
Merged PRs (30d)
5

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:

  1. We can upgrade page_fluid() and page_fixed() to use bslib::page() but for backwards compatibility, the ... elements should be handed to div(class = "container, ...).
  2. We can't redirect the ... in page_sidebar() and page_navbar() without breaking behavior since they're used by layout_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"))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the implementations and current argument handling for page(), page_fillable(), page_navbar(), page_sidebar(), page_fluid(), and page_fixed(). Compare how each function routes ... to the body, container, or layout helpers, then define and test a consistent page-level attribute API whose behavior preserves existing ... usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
bootstrap, r
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.