Skip to content

Commit 11a8281

Browse files
authored
Use semantic elements in sidebar (#580)
1 parent c8de7d8 commit 11a8281

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
* `layout_sidebar()` received a new design. The button to collapse and expand the sidebar now appears at the top edge of the sidebar, and we now use the [arrow-bar-left](https://icons.getbootstrap.com/icons/arrow-bar-left/) icon instead of [chevron-left](https://icons.getbootstrap.com/icons/chevron-left/). On mobile devices, the sidebar now fills the `layout_sidebar()` area as an overlay, rather than expanding from above the main content area. **Note** the `max_mobile_height` argument of `sidebar()` determines the maximum height of the sidebar area on mobile, but it now only applies when `open = "always"`. (#798)
4040

41+
* `layout_sidebar()` now uses an `<aside>` element for the sidebar's container and a `<header>` element for the sidebar title. The classes of each element remain the same, but the semantic meaning of the elements is now better reflected in the HTML markup. (#580)
42+
4143
## Bug fixes
4244

4345
* `toggle_switch()` now works correctly when called from within a Shiny module. `update_switch()` worked as expected, but `toggle_switch()` didn't apply the module's namespace to the `id` of the switch to be updated. (#769)
@@ -46,6 +48,8 @@
4648

4749
* A double border no longer appears when an accordion is used inside a `sidebar(open="always")` context. (#795)
4850

51+
* `layout_sidebar()` no longer gives the sidebar main content area the `role="main"` attribute. (#580)
52+
4953

5054
# bslib 0.5.1
5155

R/sidebar.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#' @param id A character string. Required if wanting to re-actively read (or
4343
#' update) the `collapsible` state in a Shiny app.
4444
#' @param title A character title to be used as the sidebar title, which will be
45-
#' wrapped in a `<div>` element with class `sidebar-title`. You can also
45+
#' wrapped in a `<header>` element with class `sidebar-title`. You can also
4646
#' provide a custom [htmltools::tag()] for the title element, in which case
4747
#' you'll likely want to give this element `class = "sidebar-title"`.
4848
#' @param bg,fg A background or foreground color. If only one of either is
@@ -119,7 +119,7 @@ sidebar <- function(
119119
}
120120

121121
if (rlang::is_bare_character(title) || rlang::is_bare_numeric(title)) {
122-
title <- div(title, class = "sidebar-title")
122+
title <- tags$header(title, class = "sidebar-title")
123123
}
124124

125125
collapse_tag <-
@@ -135,9 +135,8 @@ sidebar <- function(
135135
}
136136

137137
res <- list2(
138-
tag = tags$div(
138+
tag = tags$aside(
139139
id = id,
140-
role = "complementary",
141140
class = c("sidebar", class),
142141
hidden = if (open == "closed") NA,
143142
tags$div(
@@ -212,7 +211,6 @@ layout_sidebar <- function(
212211
}
213212

214213
main <- div(
215-
role = "main",
216214
class = "main",
217215
class = if (fillable) "bslib-gap-spacing",
218216
style = css(

man/sidebar.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/page.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
<body class="bslib-page-fill bslib-gap-spacing bslib-page-sidebar html-fill-container" style="padding:0px;gap:0px;--bslib-page-fill-mobile-height:auto;">
3636
<h1 class="bslib-page-title">Title</h1>
3737
<div class="bslib-sidebar-layout bslib-mb-spacing html-fill-item" data-bslib-sidebar-border="false" data-bslib-sidebar-border-radius="false" data-bslib-sidebar-init="TRUE" data-bslib-sidebar-open="always" data-require-bs-caller="layout_sidebar()" data-require-bs-version="5" style="--bslib-sidebar-width:250px;--bslib-sidebar-max-height-mobile:250px;">
38-
<div class="main bslib-gap-spacing html-fill-container" role="main">main</div>
39-
<div role="complementary" class="sidebar">
38+
<div class="main bslib-gap-spacing html-fill-container">main</div>
39+
<aside class="sidebar">
4040
<div class="sidebar-content bslib-gap-spacing"></div>
41-
</div>
41+
</aside>
4242
<script data-bslib-sidebar-init>bslib.Sidebar.initCollapsibleAll()</script>
4343
</div>
4444
</body>
@@ -51,10 +51,10 @@
5151
<body class="bslib-page-fill bslib-gap-spacing bslib-page-sidebar html-fill-container" style="padding:0px;gap:0px;--bslib-page-fill-mobile-height:auto;">
5252
<h1 class="bslib-page-title">Title</h1>
5353
<div class="bslib-sidebar-layout bslib-mb-spacing html-fill-item" data-bslib-sidebar-border="false" data-bslib-sidebar-border-radius="false" data-bslib-sidebar-init="TRUE" data-bslib-sidebar-open="desktop" data-require-bs-caller="layout_sidebar()" data-require-bs-version="5" style="--bslib-sidebar-width:250px;--bslib-sidebar-max-height-mobile:250px;">
54-
<div class="main bslib-gap-spacing html-fill-container" role="main">main</div>
55-
<div id="bslib-sidebar-4785" role="complementary" class="sidebar">
54+
<div class="main bslib-gap-spacing html-fill-container">main</div>
55+
<aside id="bslib-sidebar-4785" class="sidebar">
5656
<div class="sidebar-content bslib-gap-spacing">side</div>
57-
</div>
57+
</aside>
5858
<button class="collapse-toggle" type="button" title="Toggle sidebar" aria-expanded="true" aria-controls="bslib-sidebar-4785"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="bi bi-arrow-bar-left collapse-icon" style="height:;width:;fill:currentColor;vertical-align:-0.125em;" aria-hidden="true" role="img" ><path fill-rule="evenodd" d="M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5ZM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5Z"></path></svg></button>
5959
<script data-bslib-sidebar-init>bslib.Sidebar.initCollapsibleAll()</script>
6060
</div>

0 commit comments

Comments
 (0)