Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Improvements and bug fixes

* Improved the sidebar resize handle to avoid conflicts with the sidebar's native scrollbar and to better support touch devices. (#1299)

* `sidebar()` gains a `resizable` argument (default `TRUE`) to control whether the sidebar can be resized by dragging its edge on desktop (wide screen sizes). (#1299)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should go under a new features section?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incremental and minor; I'd call it an "improvement" more than a "new feature"


* Fixed `toolbar_input_button()` alignment and spacing issues. (#1290)

* The brand.yml example app (`shiny::runExample("brand.yml", package = "bslib")`) now uses `brand_pluck()` and `brand_has()` from `{brand.yml}`. (#1288)
Expand Down
8 changes: 7 additions & 1 deletion R/sidebar.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
#' @param fillable Whether or not the sidebar should be considered a fillable
#' container. When `TRUE`, the sidebar and its content can use `fill` to
#' consume available vertical space.
#' @param resizable Whether the sidebar can be resized by dragging its edge.
#' When `TRUE` (the default), a resize handle is added to the sidebar that
#' allows users to adjust the sidebar width on desktop (wide screen sizes).
#'
#' @export
sidebar <- function(
Expand All @@ -102,7 +105,8 @@ sidebar <- function(
max_height_mobile = NULL,
gap = NULL,
padding = NULL,
fillable = FALSE
fillable = FALSE,
resizable = TRUE
) {
position <- rlang::arg_match(position)
gap <- validateCssUnit(gap)
Expand Down Expand Up @@ -150,6 +154,7 @@ sidebar <- function(
max_height_mobile = max_height_mobile,
color = list(bg = bg, fg = fg),
fillable = fillable,
resizable = resizable,
attributes = dots$attribs,
children = dots$children
)
Expand Down Expand Up @@ -220,6 +225,7 @@ as.tags.bslib_sidebar <- function(x, ...) {
id = x$id,
class = c("sidebar", x$class),
hidden = if (hidden_initially) NA,
`data-resizable` = if (isTRUE(x$resizable)) NA,
if (isTRUE(x$fillable)) as_fillable_container(),
tags$div(
class = "sidebar-content bslib-gap-spacing",
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion inst/components/dist/components.css

Large diffs are not rendered by default.

88 changes: 87 additions & 1 deletion inst/components/dist/components.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions inst/components/dist/components.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions inst/components/dist/components.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/components/dist/components.min.js.map

Large diffs are not rendered by default.

62 changes: 53 additions & 9 deletions inst/components/scss/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_padding-icon)), var(--_sid
--_toggle-collective-height: calc(calc(var(--_icon-button-size) + 0.5em) * var(--_js-toggle-count-max-side, 1));

// Resize handle variables
--_resize-handle-width: var(--bslib-sidebar-resize-handle-width, 12px);
--_resize-handle-width: var(--bslib-sidebar-resize-handle-width, 8px);

@media (any-pointer: coarse) {
--_resize-handle-width: var(--bslib-sidebar-resize-handle-width, 26px);
}
--_resize-indicator-color: var(--_sidebar-fg, var(--bs-emphasis-color, black));
--_resize-indicator-color-active: var(--bslib-sidebar-resize-indicator-color-active, var(--bs-primary, #0d6efd));

Expand Down Expand Up @@ -309,20 +313,45 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_padding-icon)), var(--_sid
width: var(--_resize-handle-width);
left: calc(calc(-1 * var(--_resize-handle-width)) - 2px);
grid-column: 2;
cursor: ew-resize;
pointer-events: none;
user-select: none;
z-index: calc(#{$zindex-dropdown} + 1); // Above toggle button

// Make the handle easier to grab
// Trip area: a narrow strip at the sidebar outer edge that detects the
// mouse crossing the sidebar boundary. Positioned past the handle so
// it doesn't overlap the sidebar scrollbar beneath the handle.
// Expands when .handle-active is added to prevent accidental deactivation.
&::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
// Invisible expanded hit area
left: 0;
right: calc(-1 * var(--_resize-handle-width) - 2px);
z-index: calc(#{$zindex-dropdown} + 1); // Above toggle button
left: 100%;
width: 5px;
pointer-events: auto;
}

// When the mouse crosses the sidebar edge, JS adds .handle-active
// to show the resize cursor and expand the trip area.
&.handle-active {
cursor: ew-resize;

&::before {
left: calc(100% - 10px);
width: 24px;
}
}

// Touch users get the full handle + extended hit area
@media (any-pointer: coarse) {
pointer-events: auto;
cursor: ew-resize;

&::before {
left: 0;
width: auto;
right: calc(-1 * var(--_resize-handle-width) - 2px);
}
}

.resize-indicator {
Expand All @@ -338,14 +367,15 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_padding-icon)), var(--_sid
transition: all 0.15s ease;
}

&:hover, &:focus, &:active, &:focus {
&:hover, &:focus, &:active, &.handle-active {
.resize-indicator {
opacity: 1;
}
}

&:hover .resize-indicator,
&:focus .resize-indicator {
&:focus .resize-indicator,
&.handle-active .resize-indicator {
width: 3px;
height: 40px;
}
Expand All @@ -370,6 +400,20 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_padding-icon)), var(--_sid
// Right sidebar resize handle positioning
&.sidebar-right > .bslib-sidebar-resize-handle {
left: 2px;

&::before {
left: auto;
right: 100%;
}

&.handle-active::before {
right: calc(100% - 10px);
}
}

// Hide resize handle when sidebar is not resizable
> .sidebar:not([data-resizable]) ~ .bslib-sidebar-resize-handle {
display: none;
}

// Hide resize handle during transitions and when collapsed
Expand Down
7 changes: 6 additions & 1 deletion man/sidebar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading