-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
ref(ui): Enhance Carousel component #54747
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
ref(ui): Enhance Carousel component #54747
Conversation
d095d30
to
bb1829d
Compare
bb1829d
to
1159064
Compare
7d2c13f
to
bf518e9
Compare
window.IntersectionObserver = class IntersectionObserver { | ||
root = null; | ||
rootMargin = ''; | ||
thresholds = []; | ||
takeRecords = jest.fn(); | ||
|
||
constructor(cb: IntersectionObserverCallback) { | ||
// @ts-expect-error The callback wants just way too much stuff for our simple mock | ||
intersectionOnbserverCb = cb; | ||
} | ||
observe() {} | ||
unobserve() {} | ||
disconnect() {} | ||
}; |
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.
Do we still need this if it's in tests/js/setup
?
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.
yeah since I need to override the callback
static/app/components/carousel.tsx
Outdated
), | ||
{ | ||
root: ref.current, | ||
threshold: [0, visibleRatio, 1], |
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.
hmm why do we need the 0 & 1 thresholds? looks like we only need to update visibility when the interaction ratio crosses visibleRatio
, so shouldn't [visibleRatio]
suffice?
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.
oh good point 👍
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.
Fixed
1. Record a visibility list and use that to determine if we need to scroll left or right. This has the advantage setting isAtStart and isAtEnd as state in that we're able to be a little smarter about if an element is visibile or not. In addition here we've added a `visibleRatio` prop to the component, which lets you customize this value. 2. Use scrollIntoView. This is more robust and allows us to set a `scroll-margin` on the children. 3. Update tests to test for button clicks
bf518e9
to
d95d59e
Compare
Record a visibility list and use that to determine if we need to scroll left or right. This has the advantage setting isAtStart and isAtEnd as state in that we're able to be a little smarter about if an element is visibile or not.
In addition here we've added a
visibleRatio
prop to the component, which lets you customize this value.Use scrollIntoView. This is more robust and allows us to set a
scroll-margin
on the children.Update tests to test for button clicks