Skip to content

Commit

Permalink
Respect prefers-reduced-motion when scrolling TOC (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine committed Mar 18, 2022
1 parent 4da1bc2 commit 75e3b6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions client/lib/scroll.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export prefersReducedMotion = ->
window.matchMedia '(prefers-reduced-motion: reduce)'
.matches

## String to pass into `behavior` option for `Element.scroll`.
## https://developer.mozilla.org/en-US/docs/Web/API/Element/scroll
export scrollBehavior = ->
if prefersReducedMotion()
'instant'
else
'smooth'
3 changes: 2 additions & 1 deletion client/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {defaultHeight, emailless, messagePreviewDefault} from './settings.coffee
import {forceImgReload} from './lib/forceImgReload'
import {useElementWidth} from './lib/resize'
import {setMigrateSafe, migrateWant} from './lib/migrate'
import {scrollBehavior} from './lib/scroll'
import {allEmoji} from '/lib/emoji'
import {availableFormats, formatBody, formatFile, formatFileDescription, formatTitleOrFilename, parseCoauthorAuthorUrl, parseCoauthorMessageUrl} from '/lib/formats'
import {ancestorMessages, messageDiffsExpanded, messageNeighbors, sortedMessageReaders} from '/lib/messages'
Expand Down Expand Up @@ -2313,7 +2314,7 @@ export WrappedSubmessage = React.memo ({message, read}) ->
item = item.offsetParent
toc.scroll
top: itemTop - msgTop - 9 # fudge factor to align heading with toc item
behavior: 'smooth'
behavior: scrollBehavior()

<div className="panel message #{messagePanelClass message, editing}" data-message={message._id} id={message._id} ref={setRef}>
<div className="panel-heading clearfix" onClick={showTOC}>
Expand Down

0 comments on commit 75e3b6f

Please sign in to comment.