Skip to content

Commit 5d131ce

Browse files
committed
add support for keyboard navigation in scroll view #3515
1 parent 5248015 commit 5d131ce

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

dist/reveal.esm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.esm.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reveal.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/controllers/scrollview.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default class ScrollView {
277277
const pageHeight = useCompactLayout ? compactHeight : viewportHeight;
278278

279279
// The height that needs to be scrolled between scroll triggers
280-
const scrollTriggerHeight = useCompactLayout ? compactHeight : viewportHeight;
280+
this.scrollTriggerHeight = useCompactLayout ? compactHeight : viewportHeight;
281281

282282
this.viewportElement.style.setProperty( '--page-height', pageHeight + 'px' );
283283
this.viewportElement.style.scrollSnapType = typeof config.scrollSnap === 'string' ? `y ${config.scrollSnap}` : '';
@@ -333,12 +333,12 @@ export default class ScrollView {
333333
for( let i = 0; i < totalScrollTriggerCount + 1; i++ ) {
334334
const triggerStick = document.createElement( 'div' );
335335
triggerStick.className = 'scroll-snap-point';
336-
triggerStick.style.height = scrollTriggerHeight + 'px';
336+
triggerStick.style.height = this.scrollTriggerHeight + 'px';
337337
triggerStick.style.scrollSnapAlign = useCompactLayout ? 'center' : 'start';
338338
page.pageElement.appendChild( triggerStick );
339339

340340
if( i === 0 ) {
341-
triggerStick.style.marginTop = -scrollTriggerHeight + 'px';
341+
triggerStick.style.marginTop = -this.scrollTriggerHeight + 'px';
342342
}
343343
}
344344

@@ -355,7 +355,7 @@ export default class ScrollView {
355355
}
356356

357357
// Add scroll padding based on how many scroll triggers we have
358-
page.scrollPadding = scrollTriggerHeight * totalScrollTriggerCount;
358+
page.scrollPadding = this.scrollTriggerHeight * totalScrollTriggerCount;
359359

360360
// The total height including scrollable space
361361
page.totalHeight = page.pageHeight + page.scrollPadding;
@@ -699,6 +699,24 @@ export default class ScrollView {
699699

700700
}
701701

702+
/**
703+
* Scroll to the previous page.
704+
*/
705+
prev() {
706+
707+
this.viewportElement.scrollTop -= this.scrollTriggerHeight;
708+
709+
}
710+
711+
/**
712+
* Scroll to the next page.
713+
*/
714+
next() {
715+
716+
this.viewportElement.scrollTop += this.scrollTriggerHeight;
717+
718+
}
719+
702720
/**
703721
* Scrolls the given slide element into view.
704722
*

js/reveal.js

+18
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,9 @@ export default function( revealElement, options ) {
24992499

25002500
navigationHistory.hasNavigatedHorizontally = true;
25012501

2502+
// Scroll view navigation is handled independently
2503+
if( scrollView.isActive() ) return scrollView.prev();
2504+
25022505
// Reverse for RTL
25032506
if( config.rtl ) {
25042507
if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().left ) {
@@ -2516,6 +2519,9 @@ export default function( revealElement, options ) {
25162519

25172520
navigationHistory.hasNavigatedHorizontally = true;
25182521

2522+
// Scroll view navigation is handled independently
2523+
if( scrollView.isActive() ) return scrollView.next();
2524+
25192525
// Reverse for RTL
25202526
if( config.rtl ) {
25212527
if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().right ) {
@@ -2531,6 +2537,9 @@ export default function( revealElement, options ) {
25312537

25322538
function navigateUp({skipFragments=false}={}) {
25332539

2540+
// Scroll view navigation is handled independently
2541+
if( scrollView.isActive() ) return scrollView.prev();
2542+
25342543
// Prioritize hiding fragments
25352544
if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().up ) {
25362545
slide( indexh, indexv - 1 );
@@ -2542,6 +2551,9 @@ export default function( revealElement, options ) {
25422551

25432552
navigationHistory.hasNavigatedVertically = true;
25442553

2554+
// Scroll view navigation is handled independently
2555+
if( scrollView.isActive() ) return scrollView.next();
2556+
25452557
// Prioritize revealing fragments
25462558
if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().down ) {
25472559
slide( indexh, indexv + 1 );
@@ -2557,6 +2569,9 @@ export default function( revealElement, options ) {
25572569
*/
25582570
function navigatePrev({skipFragments=false}={}) {
25592571

2572+
// Scroll view navigation is handled independently
2573+
if( scrollView.isActive() ) return scrollView.prev();
2574+
25602575
// Prioritize revealing fragments
25612576
if( skipFragments || fragments.prev() === false ) {
25622577
if( availableRoutes().up ) {
@@ -2596,6 +2611,9 @@ export default function( revealElement, options ) {
25962611
navigationHistory.hasNavigatedHorizontally = true;
25972612
navigationHistory.hasNavigatedVertically = true;
25982613

2614+
// Scroll view navigation is handled independently
2615+
if( scrollView.isActive() ) return scrollView.next();
2616+
25992617
// Prioritize revealing fragments
26002618
if( skipFragments || fragments.next() === false ) {
26012619

0 commit comments

Comments
 (0)