-
Notifications
You must be signed in to change notification settings - Fork 131
[C-607] Fix modal scroll bar #6158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useEffect, useRef, useMemo } from 'react' | ||
| import { useEffect, useRef, useMemo, forwardRef, Ref, useCallback } from 'react' | ||
|
|
||
| import { ResizeObserver } from '@juggle/resize-observer' | ||
| import cn from 'classnames' | ||
|
|
@@ -15,64 +15,71 @@ import { ScrollbarProps } from './types' | |
| * `Scrollbar` uses react-perfect-scrollbar (https://www.npmjs.com/package/react-perfect-scrollbar) | ||
| * under the hood. For advanced use cases, refer to the documentation. | ||
| */ | ||
| export const Scrollbar = ({ | ||
| children, | ||
| className, | ||
| id, | ||
| forward, | ||
| ...props | ||
| }: ScrollbarProps) => { | ||
| // Do not remove: | ||
| // useMeasure ref is required for infinite scrolling to work | ||
| const [ref] = useMeasure({ polyfill: ResizeObserver }) | ||
| const timerRef = useRef<NodeJS.Timeout | null>(null) | ||
| const elementId = useMemo(() => id || uniqueId('scrollbar-'), [id]) | ||
| export const Scrollbar = forwardRef( | ||
| ( | ||
| { children, className, id, forward, isHidden, ...props }: ScrollbarProps, | ||
| forwardedRef: Ref<PerfectScrollbar> | ||
| ) => { | ||
| // Do not remove: | ||
| // useMeasure ref is required for infinite scrolling to work | ||
| const [ref] = useMeasure({ polyfill: ResizeObserver }) | ||
| const timerRef = useRef<NodeJS.Timeout | null>(null) | ||
| const elementId = useMemo(() => id || uniqueId('scrollbar-'), [id]) | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| useEffect(() => { | ||
| return () => { | ||
| if (timerRef.current !== null) { | ||
| clearTimeout(timerRef.current) | ||
| } | ||
| } | ||
| }, []) | ||
|
|
||
| const hideScrollbar = useCallback(() => { | ||
| const element = document.getElementById(elementId) | ||
| if (element) { | ||
| element.classList.remove('scrollbar--hovered-visible') | ||
| } | ||
| if (timerRef.current !== null) { | ||
| clearTimeout(timerRef.current) | ||
| } | ||
| } | ||
| }, []) | ||
|
|
||
| const hideScrollbar = () => { | ||
| const element = document.getElementById(elementId) | ||
| if (element) { | ||
| element.classList.remove('scrollbar--hovered-visible') | ||
| } | ||
| if (timerRef.current !== null) { | ||
| clearTimeout(timerRef.current) | ||
| } | ||
| } | ||
| }, [elementId, timerRef]) | ||
|
|
||
| const showScrollbar = () => { | ||
| const element = document.getElementById(elementId) | ||
| if (element) { | ||
| element.classList.add('scrollbar--hovered-visible') | ||
| } | ||
| if (timerRef.current !== null) { | ||
| clearTimeout(timerRef.current) | ||
| } | ||
| timerRef.current = setTimeout(() => { | ||
| const showScrollbar = useCallback(() => { | ||
| if (isHidden) return | ||
| const element = document.getElementById(elementId) | ||
| if (element) { | ||
| element.classList.remove('scrollbar--hovered-visible') | ||
| element.classList.add('scrollbar--hovered-visible') | ||
| } | ||
| }, 1400) | ||
| } | ||
| if (timerRef.current !== null) { | ||
| clearTimeout(timerRef.current) | ||
| } | ||
| timerRef.current = setTimeout(() => { | ||
| const element = document.getElementById(elementId) | ||
| if (element) { | ||
| element.classList.remove('scrollbar--hovered-visible') | ||
| } | ||
| }, 1400) | ||
| }, [elementId, timerRef, isHidden]) | ||
|
|
||
| useEffect(() => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the only diff in the file other than a |
||
| if (isHidden) { | ||
| hideScrollbar() | ||
| } | ||
| }, [isHidden, hideScrollbar]) | ||
|
|
||
| const content = forward ? children : <div ref={ref}>{children}</div> | ||
| const content = forward ? children : <div ref={ref}>{children}</div> | ||
|
|
||
| return ( | ||
| <PerfectScrollbar | ||
| {...props} | ||
| id={elementId} | ||
| className={cn(styles.scrollbar, className)} | ||
| onMouseEnter={showScrollbar} | ||
| onMouseLeave={hideScrollbar} | ||
| > | ||
| {content} | ||
| </PerfectScrollbar> | ||
| ) | ||
| } | ||
| return ( | ||
| <PerfectScrollbar | ||
| {...props} | ||
| ref={forwardedRef} | ||
| id={elementId} | ||
| className={cn(styles.scrollbar, className)} | ||
| onMouseEnter={showScrollbar} | ||
| onMouseLeave={hideScrollbar} | ||
| > | ||
| {content} | ||
| </PerfectScrollbar> | ||
| ) | ||
| } | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't tell without looking at docs what this was - in our case, this is
isOpenand this works because wesetIsDoneOpening(true)with asetImmediateso it executes next in the event stack?Does our version of
react-springhaveonRest? I think that might make more sense: https://www.react-spring.dev/docs/advanced/events#onrestUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on rest is only for spring not transition :/
we should change this to spring, but i didn't want to chew that off now.
but your analysis is correct!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, the docs for the new version say it's both! Must not be supported in our version