2020import org .patternfly .core .Aria ;
2121import org .patternfly .core .LanguageDirection ;
2222import org .patternfly .core .ObservableValue ;
23-
2423import elemental2 .dom .HTMLElement ;
2524import elemental2 .dom .Node ;
2625import elemental2 .dom .NodeList ;
3332import static org .jboss .elemento .Elements .setVisible ;
3433import static org .jboss .elemento .EventType .bind ;
3534import static org .jboss .elemento .EventType .resize ;
35+ import static org .jboss .elemento .EventType .scroll ;
3636import static org .patternfly .component .button .Button .button ;
3737import static org .patternfly .core .Aria .hidden ;
3838import static org .patternfly .core .Aria .label ;
@@ -64,6 +64,7 @@ public class ScrollButtons {
6464 private final ObservableValue <Boolean > disableForwardScrollButton ;
6565
6666 private double scrollTimeout ;
67+ private HandlerRegistration scrollHandler ;
6768 private HandlerRegistration resizeHandler ;
6869 private HandlerRegistration transitionEndHandler ;
6970
@@ -90,9 +91,12 @@ public ScrollButtons(HTMLElement component, HTMLElement itemsContainer, String c
9091 .aria (hidden , true )
9192 .aria (label , "Scroll forward" ))
9293 .element ();
94+ setVisible (scrollBackContainer , false );
95+ setVisible (scrollForwardContainer , false );
9396 }
9497
9598 public void attach () {
99+ scrollHandler = bind (itemsContainer , scroll , e -> updateScrollState ());
96100 scrollBack .onClick ((e , b ) -> scrollBack ());
97101 scrollForward .onClick ((e , b ) -> scrollForward ());
98102 enableScrollButtons .subscribe ((current , previous ) -> {
@@ -125,6 +129,9 @@ public void attach() {
125129
126130 public void detach () {
127131 clearTimeout (scrollTimeout );
132+ if (scrollHandler != null ) {
133+ scrollHandler .removeHandler ();
134+ }
128135 if (resizeHandler != null ) {
129136 resizeHandler .removeHandler ();
130137 }
0 commit comments