-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Carousel: Drag event based index callback #33092
Merged
Mitch-At-Work
merged 3 commits into
microsoft:master
from
Mitch-At-Work:user/mifraser/carousel-drag-index-change
Oct 28, 2024
Merged
Carousel: Drag event based index callback #33092
Mitch-At-Work
merged 3 commits into
microsoft:master
from
Mitch-At-Work:user/mifraser/carousel-drag-index-change
Oct 28, 2024
Conversation
This file contains 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
📊 Bundle size report
Unchanged fixtures
|
Perf Analysis (
|
Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
---|---|---|---|---|---|
FluentProviderWithTheme | virtual-rerender-with-unmount | 85 | 89 | 10 | Possible regression |
All results
Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
---|---|---|---|---|---|
Avatar | mount | 655 | 641 | 5000 | |
Button | mount | 308 | 303 | 5000 | |
Field | mount | 1115 | 1162 | 5000 | |
FluentProvider | mount | 710 | 710 | 5000 | |
FluentProviderWithTheme | mount | 87 | 95 | 10 | |
FluentProviderWithTheme | virtual-rerender | 39 | 38 | 10 | |
FluentProviderWithTheme | virtual-rerender-with-unmount | 85 | 89 | 10 | Possible regression |
MakeStyles | mount | 870 | 843 | 50000 | |
Persona | mount | 1775 | 1764 | 5000 | |
SpinButton | mount | 1432 | 1345 | 5000 | |
SwatchPicker | mount | 1657 | 1652 | 5000 |
fabricteam
reviewed
Oct 21, 2024
change/@fluentui-react-carousel-a81a3faa-36db-4ee8-b041-10bc72927e35.json
Show resolved
Hide resolved
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.
The problem that we have there is kinda simple: Embla does not provide access to events.
IMO, it would nicer to solve it via a custom plugin:
export type PointerEventPluginOptions = {
onSelectViaDrag: (event: PointerEvent | MouseEvent, index: number) => void;
};
export type PointerEventPlugin = CreatePluginType<{}, PointerEventPluginOptions>;
function PointerEventPlugin(options: PointerEventPluginOptions): PointerEventPlugin {
let emblaApi: EmblaCarouselType;
let pointerEvent: PointerEvent | MouseEvent | undefined;
function documentDownListener(event: PointerEvent | MouseEvent) {
const targetDocument = emblaApi.containerNode().ownerDocument;
pointerEvent = event;
targetDocument.removeEventListener('mousedown', documentDownListener);
targetDocument.removeEventListener('pointerdown', documentDownListener);
}
function pointerUpListener() {
const targetDocument = emblaApi.containerNode().ownerDocument;
targetDocument.addEventListener('mousedown', documentDownListener);
targetDocument.addEventListener('pointerdown', documentDownListener);
}
function selectListener() {
if (pointerEvent) {
const newIndex = emblaApi.selectedScrollSnap() ?? 0;
options.onSelectViaDrag(pointerEvent, newIndex);
pointerEvent = undefined;
}
}
function init(emblaApiInstance: EmblaCarouselType, optionsHandler: OptionsHandlerType): void {
emblaApi = emblaApiInstance;
emblaApi.on('pointerUp', pointerUpListener);
emblaApi.on('select', selectListener);
}
function destroy(): void {
emblaApi.off('pointerUp', pointerUpListener);
emblaApi.off('select', selectListener);
}
return {
name: 'pointerEvent',
options,
init,
destroy,
};
}
packages/react-components/react-carousel/stories/src/Carousel/CarouselControlled.stories.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-carousel/library/src/components/CarouselContext.types.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-carousel/library/src/components/useEmblaCarousel.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-carousel/library/src/components/useEmblaCarousel.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-carousel/library/src/components/useEmblaCarousel.ts
Show resolved
Hide resolved
packages/react-components/react-carousel/stories/src/Carousel/CarouselControlled.stories.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-carousel/stories/src/Carousel/CarouselDefault.stories.tsx
Outdated
Show resolved
Hide resolved
Mitch-At-Work
force-pushed
the
user/mifraser/carousel-drag-index-change
branch
from
October 25, 2024 20:02
aecd0ce
to
fbbb055
Compare
packages/react-components/react-carousel/stories/src/Carousel/CarouselEventing.stories.tsx
Show resolved
Hide resolved
layershifter
approved these changes
Oct 25, 2024
Mitch-At-Work
force-pushed
the
user/mifraser/carousel-drag-index-change
branch
from
October 28, 2024 17:29
a51ba44
to
41d6c84
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previous Behavior
Carousel was calling the index change callback on Button and Focus events only, preventing users from receiving callback information about drag events.
New Behavior
Drag event now correctly emits a native DOM event with type 'drag', this is driven directly by Embla engine and hence is native.