Skip to content

Commit a3bc7f6

Browse files
frankieyanclaude
andcommitted
feat(sidebar): warn when a resize handle has no usable bounds
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 34208f0 commit a3bc7f6

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/sidebar/sidebar.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ the inner edge (right for `align="start"`, left for `align="end"`), drives a
8989
render-free pointer drag, and commits the width through `onWidthChange` on
9090
pointer up. Width is controlled by the consumer.
9191

92+
A resizable sidebar needs `width`, `minWidth`, and `maxWidth` on `Sidebar` (with
93+
`minWidth` below `maxWidth`), plus `resizeStep` for keyboard steps and
94+
`defaultWidth` for the double-click reset. Without a usable range the handle
95+
renders and focuses but cannot move, and logs a development warning.
96+
9297
<Canvas of={SidebarStories.Resizable} />
9398

9499
Keyboard support, from the separator:

src/sidebar/sidebar.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ describe('errors', () => {
456456
describe('accessibility', () => {
457457
it('has no axe violations as a docked nav', async () => {
458458
const { container } = render(
459-
<Sidebar align="start" isOpen id="nav">
459+
<Sidebar align="start" isOpen id="nav" width={280} minWidth={210} maxWidth={420}>
460460
<SidebarContent>
461461
<nav aria-label="Main navigation">
462462
<a href="#projects">Projects</a>

src/sidebar/sidebar.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,19 @@ function SidebarResizeHandle({
484484
const minValuePx = minWidth ?? committedWidth
485485
const maxValuePx = maxWidth ?? committedWidth
486486

487+
const hasResizeRange = minWidth != null && maxWidth != null && minWidth < maxWidth
488+
if (width == null) {
489+
// eslint-disable-next-line no-console
490+
console.warn(
491+
'[Sidebar]: <SidebarResizeHandle> needs a controlled `width` on <Sidebar> to resize; the handle renders but cannot move.',
492+
)
493+
} else if (!hasResizeRange) {
494+
// eslint-disable-next-line no-console
495+
console.warn(
496+
'[Sidebar]: <SidebarResizeHandle> needs `minWidth` and `maxWidth` (with minWidth < maxWidth) on <Sidebar>; without a range the handle renders but cannot move.',
497+
)
498+
}
499+
487500
const { currentValuePx, onDoubleClick, onKeyDown, onPointerDown } = useResizablePanel({
488501
cssVariable: SIDEBAR_WIDTH_VAR,
489502
defaultValuePx: defaultWidth ?? committedWidth,

0 commit comments

Comments
 (0)