Skip to content
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

fix: fix keyboard controls with carousel #925

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions frontend/src/plugins/layout/CarouselPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const CarouselComponent = ({
const [isFullscreen, setIsFullscreen] = React.useState(false);

useEventListener(document, "fullscreenchange", () => {
if (document.fullscreenElement) {
el.current?.swiper.keyboard.enable();
} else {
el.current?.swiper.keyboard.disable();
}
setIsFullscreen(!!document.fullscreenElement);
});

Expand All @@ -86,8 +91,8 @@ const CarouselComponent = ({
// touch controls interfere with UI elements
simulateTouch={false}
keyboard={{
enabled: true,
onlyInViewport: true,
// Only enable keyboard controls when in fullscreen
enabled: isFullscreen,
}}
navigation={true}
pagination={{
Expand All @@ -99,6 +104,15 @@ const CarouselComponent = ({
return (
<SwiperSlide key={index}>
<div
onKeyDown={(e) => {
// If the target is from a marimo element, stop propagation
if (
e.target instanceof HTMLElement &&
e.target.tagName.toLocaleLowerCase().startsWith("marimo-")
) {
e.stopPropagation();
}
}}
Comment on lines +107 to +115
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we do this with onMouseDown too and then re-enable simulateTouch=True?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i just tried - got pretty close. it works with sliders, but not with altair, so lets just keep it off

className={cn(
"h-full w-full flex items-center justify-center box-border overflow-hidden",
isFullscreen ? "p-20" : "p-6",
Expand Down
Loading