File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
packages/react/src/components/Tabs Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -235,4 +235,35 @@ test.describe('@avt Tabs', () => {
235
235
await page . keyboard . press ( 'Delete' ) ;
236
236
await expect ( page . getByRole ( 'tab' , { name : 'Tab label 4' } ) ) . toBeHidden ( ) ;
237
237
} ) ;
238
+
239
+ test ( '@avt-keyboard-nav - horizontal manual scroll' , async ( { page } ) => {
240
+ await visitStory ( page , {
241
+ component : 'Tabs' ,
242
+ id : 'components-tabs--default' ,
243
+ globals : {
244
+ theme : 'white' ,
245
+ } ,
246
+ } ) ;
247
+
248
+ // Set viewport size so scroll buttons appear
249
+ await page . setViewportSize ( {
250
+ width : 200 ,
251
+ height : 480 ,
252
+ } ) ;
253
+ await page . waitForSelector ( '.cds--tab--overflow-nav-button--next' , {
254
+ state : 'visible' ,
255
+ } ) ;
256
+
257
+ // Right scroll button should disappear after manually scrolling horizontally to end of tabs
258
+ const tabList = page . locator ( '.cds--tab--list' ) ;
259
+ const lastElement = page . getByText ( 'Settings' ) . nth ( 1 ) ;
260
+ const nextButton = page . getByLabel ( 'Scroll right' ) ;
261
+ await tabList . hover ( ) ;
262
+ await lastElement . scrollIntoViewIfNeeded ( ) ;
263
+ await page . waitForSelector ( '.cds--tab--overflow-nav-button--next' , {
264
+ state : 'hidden' ,
265
+ timeout : 1000 ,
266
+ } ) ;
267
+ await expect ( nextButton ) . toBeHidden ( ) ;
268
+ } ) ;
238
269
} ) ;
Original file line number Diff line number Diff line change @@ -529,9 +529,12 @@ function TabList({
529
529
530
530
const tabs = useRef < TabElement [ ] > ( [ ] ) ;
531
531
const debouncedOnScroll = useCallback ( ( ) => {
532
- return debounce ( ( event ) => {
533
- setScrollLeft ( event . target . scrollLeft ) ;
532
+ const updateScroll = debounce ( ( ) => {
533
+ if ( ref . current ) {
534
+ setScrollLeft ( ref . current . scrollLeft ) ;
535
+ }
534
536
} , scrollDebounceWait ) ;
537
+ updateScroll ( ) ;
535
538
} , [ scrollDebounceWait ] ) ;
536
539
537
540
function onKeyDown ( event : KeyboardEvent ) {
You can’t perform that action at this time.
0 commit comments