Skip to content

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

Merged

Conversation

evanpurkhiser
Copy link
Member

  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

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Aug 15, 2023
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-ui-enhance-carousel-component branch from d095d30 to bb1829d Compare August 15, 2023 01:13
@evanpurkhiser evanpurkhiser requested a review from a team August 15, 2023 01:14
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-ui-enhance-carousel-component branch from bb1829d to 1159064 Compare August 15, 2023 01:16
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-ui-enhance-carousel-component branch 2 times, most recently from 7d2c13f to bf518e9 Compare August 15, 2023 01:34
Comment on lines +9 to +22
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() {}
};
Copy link
Member

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?

Copy link
Member Author

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

),
{
root: ref.current,
threshold: [0, visibleRatio, 1],
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good point 👍

Copy link
Member Author

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
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-ui-enhance-carousel-component branch from bf518e9 to d95d59e Compare August 15, 2023 17:08
@evanpurkhiser evanpurkhiser enabled auto-merge (squash) August 15, 2023 17:17
@evanpurkhiser evanpurkhiser merged commit fc2eb09 into master Aug 15, 2023
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-ui-enhance-carousel-component branch August 15, 2023 17:34
@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants