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

WRR-11077: Fixed Scroller to prevent the native scrolling behavior caused by keydown events when the popup is opened #1756

Merged
merged 9 commits into from
Dec 5, 2024
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install:
- npm install
- npm link
- popd
- git clone --branch=develop --depth 1 https://github.com/enactjs/enact ../enact
- git clone --branch=feature/WRR-11077 --depth 1 https://github.com/enactjs/enact ../enact
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to revert the change before merging.

- pushd ../enact
- npm install
- npm run lerna exec -- --ignore enact-sampler --concurrency 1 -- npm --no-package-lock install
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The following is a curated list of changes in the Enact sandstone module, newest changes on the top.

## [unreleased]

### Fixed

- `sandstone/Scroller` to prevent the native scrolling behavior caused by keydown events when a popup is open

## [3.0.0-alpha.3] - 2024-12-02

### Added
Expand Down
32 changes: 32 additions & 0 deletions samples/sampler/stories/qa/Scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,3 +1284,35 @@ export const WithContentContainerOnFocus = () => {
};

WithContentContainerOnFocus.storyName = 'With Content Container';

export const WithFixedPopupPanels = () => {
const [open, setOpenState] = useState(false);

const handleOpen = useCallback(() => {
setOpenState(true);
}, [setOpenState]);

const handleClose = useCallback(() => {
setOpenState(false);
}, [setOpenState]);

return (
<>
<Scroller>
<Button onClick={handleOpen}>
Open FixedPopupPanels
</Button>
<div style={{height: ri.scaleToRem(2400)}} />
</Scroller>
<FixedPopupPanels open={open} onClose={handleClose}>
<FixedPopupPanels.Panel>
<Header title="Panel" />
<Item>Item A</Item>
<Item>Item B</Item>
</FixedPopupPanels.Panel>
</FixedPopupPanels>
</>
);
};

WithFixedPopupPanels.storyName = 'With FixedPopupPanels';
12 changes: 11 additions & 1 deletion useScroll/useScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import {forward} from '@enact/core/handle';
import platform from '@enact/core/platform';
import Spotlight from '@enact/spotlight';
import Spotlight, {getDirection} from '@enact/spotlight';
import {spottableClass} from '@enact/spotlight/Spottable';
import {getContainerId} from '@enact/spotlight/src/container';
import {getTargetByDirectionFromPosition} from '@enact/spotlight/src/target';
Expand Down Expand Up @@ -270,6 +270,13 @@
}
}

function preventScroll (ev) {
if (Spotlight.isPaused() && getDirection(ev.keyCode)) {
ev.preventDefault();
ev.stopPropagation();

Check warning on line 276 in useScroll/useScroll.js

View check run for this annotation

Codecov / codecov/patch

useScroll/useScroll.js#L275-L276

Added lines #L275 - L276 were not covered by tests
}
}

// Return

return {
Expand All @@ -285,6 +292,7 @@
handleTouchStart,
handleWheel,
removeEventListeners,
preventScroll,
scrollbarProps,
scrollStopOnScroll,
scrollTo,
Expand Down Expand Up @@ -405,6 +413,7 @@
handleTouchStart,
handleWheel,
removeEventListeners,
preventScroll, // scrollMode 'native'
scrollbarProps,
scrollStopOnScroll, // scrollMode 'native'
scrollTo,
Expand All @@ -417,6 +426,7 @@
if (scrollMode === 'translate') {
scrollProps.stop = stop;
} else {
scrollProps.preventScroll = preventScroll;
scrollProps.scrollStopOnScroll = scrollStopOnScroll;
scrollProps.start = start;
}
Expand Down