File tree Expand file tree Collapse file tree
docs/app/javascript/controllers/ruby_ui
gem/lib/ruby_ui/message_scroller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -309,16 +309,27 @@ export default class extends Controller {
309309 return scrollHeight - ( scrollTop + clientHeight ) <= this . endThresholdValue ;
310310 }
311311
312+ isAtStart ( ) {
313+ if ( ! this . hasViewportTarget ) return true ;
314+ return this . viewportTarget . scrollTop <= this . endThresholdValue ;
315+ }
316+
312317 hasOverflow ( ) {
313318 if ( ! this . hasViewportTarget ) return false ;
314319 return this . viewportTarget . scrollHeight - this . viewportTarget . clientHeight > this . endThresholdValue ;
315320 }
316321
322+ // Each button activates based on its own direction: an end button when the
323+ // reader is away from the bottom, a start button when away from the top.
317324 updateButton ( ) {
318325 if ( ! this . hasButtonTarget ) return ;
319- const active = this . hasOverflow ( ) && ! this . isAtEnd ( ) ;
320- this . buttonTarget . setAttribute ( "data-active" , active ? "true" : "false" ) ;
321- // Remove the inert button from the tab order so there are no ghost stops.
322- this . buttonTarget . setAttribute ( "tabindex" , active ? "0" : "-1" ) ;
326+ const overflow = this . hasOverflow ( ) ;
327+ this . buttonTargets . forEach ( ( button ) => {
328+ const toStart = button . dataset . direction === "start" ;
329+ const active = overflow && ( toStart ? ! this . isAtStart ( ) : ! this . isAtEnd ( ) ) ;
330+ button . setAttribute ( "data-active" , active ? "true" : "false" ) ;
331+ // Remove the inert button from the tab order so there are no ghost stops.
332+ button . setAttribute ( "tabindex" , active ? "0" : "-1" ) ;
333+ } ) ;
323334 }
324335}
Original file line number Diff line number Diff line change @@ -309,16 +309,27 @@ export default class extends Controller {
309309 return scrollHeight - ( scrollTop + clientHeight ) <= this . endThresholdValue ;
310310 }
311311
312+ isAtStart ( ) {
313+ if ( ! this . hasViewportTarget ) return true ;
314+ return this . viewportTarget . scrollTop <= this . endThresholdValue ;
315+ }
316+
312317 hasOverflow ( ) {
313318 if ( ! this . hasViewportTarget ) return false ;
314319 return this . viewportTarget . scrollHeight - this . viewportTarget . clientHeight > this . endThresholdValue ;
315320 }
316321
322+ // Each button activates based on its own direction: an end button when the
323+ // reader is away from the bottom, a start button when away from the top.
317324 updateButton ( ) {
318325 if ( ! this . hasButtonTarget ) return ;
319- const active = this . hasOverflow ( ) && ! this . isAtEnd ( ) ;
320- this . buttonTarget . setAttribute ( "data-active" , active ? "true" : "false" ) ;
321- // Remove the inert button from the tab order so there are no ghost stops.
322- this . buttonTarget . setAttribute ( "tabindex" , active ? "0" : "-1" ) ;
326+ const overflow = this . hasOverflow ( ) ;
327+ this . buttonTargets . forEach ( ( button ) => {
328+ const toStart = button . dataset . direction === "start" ;
329+ const active = overflow && ( toStart ? ! this . isAtStart ( ) : ! this . isAtEnd ( ) ) ;
330+ button . setAttribute ( "data-active" , active ? "true" : "false" ) ;
331+ // Remove the inert button from the tab order so there are no ghost stops.
332+ button . setAttribute ( "tabindex" , active ? "0" : "-1" ) ;
333+ } ) ;
323334 }
324335}
You can’t perform that action at this time.
0 commit comments