Skip to content

Commit

Permalink
fix(HTL-103087): menu jumps to top of screen (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
fareedahmad1 committed Apr 24, 2024
1 parent 92747dd commit b5311a0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-menu",
"comment": "fix when the menu opens the page scrolls to the top",
"type": "patch"
}
],
"packageName": "pcln-menu"
}
28 changes: 27 additions & 1 deletion packages/menu/src/Menu/Menu.stories.jsx
Expand Up @@ -2,7 +2,7 @@ import { userEvent, within } from '@storybook/testing-library'
import React, { useState } from 'react'
import { argTypes, defaultArgs } from './Menu.stories.args'
import { Bed as BedIcon } from 'pcln-icons'
import { Box, Button, ButtonChip, Dialog, Divider, Flex, Link, Text } from 'pcln-design-system'
import { Absolute, Box, Button, ButtonChip, Dialog, Divider, Flex, Link, Text } from 'pcln-design-system'
import { listItems, currencies } from '../../test/mocks/Menu'
import Menu from './Menu'
import MenuItem from '../MenuItem'
Expand Down Expand Up @@ -240,3 +240,29 @@ export const WithCustomPlacement = SingleLineTemplate.bind({})
WithCustomPlacement.args = {
placement: 'bottom',
}

export const BelowPageFold = (args) => {
const [value, setValue] = useState('one')
const [isOpen, setIsOpen] = useState(false)

return (
<div>
<Text>Scroll down to menu</Text>
<Absolute top={'110vh'}>
<Menu buttonText='Menu' width={275} {...args} isFloating={false} isOpen={isOpen}>
{listItems.map((item, index) => {
const selected = value === item.value
const onClick = () => setValue(item.value)
return (
<MenuItem key={index} onClick={onClick} selected={selected}>
<Flex flexDirection='column' alignItems='flex-start'>
<Text textStyle='paragraph'>{item.label}</Text>
</Flex>
</MenuItem>
)
})}
</Menu>
</Absolute>
</div>
)
}
2 changes: 1 addition & 1 deletion packages/menu/src/MenuList/MenuList.jsx
Expand Up @@ -50,7 +50,7 @@ function MenuList({ id, children, color, size, height, handleClose }) {

useEffect(() => {
setCurrentItemId(currentItemRef.current?.id)
currentItemRef.current?.focus()
currentItemRef.current?.focus({ preventScroll: true })
}, [])

const handleKeyDown = useCallback((evt) => {
Expand Down

0 comments on commit b5311a0

Please sign in to comment.