diff --git a/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx b/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx index d04efff54258..1aef91e37405 100644 --- a/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx +++ b/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx @@ -123,3 +123,37 @@ export const CustomSize = () => ( ))} ); + +export const FocusableVertical = () => ( + + {list((i) => ( + + {i} +
+
+ ))} +
+); + +export const FocusableHorizontal = () => ( + +
+ {list((i) => ( + {i} + ))} +
+
+); + +export const FocusableBoth = () => ( + + {list((i) => ( + + {list((ii) => ( + {ii * i} + ))} +
+
+ ))} +
+); diff --git a/code/core/src/components/components/ScrollArea/ScrollArea.tsx b/code/core/src/components/components/ScrollArea/ScrollArea.tsx index 8a45f2056881..edbca799f1a9 100644 --- a/code/core/src/components/components/ScrollArea/ScrollArea.tsx +++ b/code/core/src/components/components/ScrollArea/ScrollArea.tsx @@ -11,6 +11,11 @@ export interface ScrollAreaProps { offset?: number; scrollbarSize?: number; scrollPadding?: number | string; + /** + * Set this to define a tabIndex on the scrollable content; only needed when content has no + * interactive elements. + */ + focusable?: boolean; } const ScrollAreaRoot = styled(ScrollAreaPrimitive.Root)<{ scrollbarsize: number; offset: number }>( @@ -23,10 +28,18 @@ const ScrollAreaRoot = styled(ScrollAreaPrimitive.Root)<{ scrollbarsize: number; }) ); -const ScrollAreaViewport = styled(ScrollAreaPrimitive.Viewport)({ - width: '100%', - height: '100%', -}); +const ScrollAreaViewport = styled(ScrollAreaPrimitive.Viewport)<{ focusable: boolean }>( + ({ focusable, theme }) => ({ + width: '100%', + height: '100%', + '&:focus': focusable + ? { + outline: `2px solid ${theme.color.secondary}`, + outlineOffset: -2, + } + : {}, + }) +); const ScrollAreaScrollbar = styled(ScrollAreaPrimitive.Scrollbar)<{ offset: number; @@ -89,11 +102,17 @@ export const ScrollArea = forwardRef( scrollbarSize = 6, scrollPadding = 0, className, + focusable = false, }, ref ) => ( - + {children} {horizontal && ( diff --git a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx index 58286cec773e..494afdc587e2 100644 --- a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx +++ b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx @@ -91,7 +91,7 @@ const Wrapper = styled.div( ); const UnstyledScroller = ({ children, className }: ScrollAreaProps) => ( - + {children} );