Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

[FRONT-476] make Menu scrollable #2618

Merged
merged 34 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a53987c
♻️ merge the outline element and the list element
farazatarodi Apr 5, 2023
f6cb63c
🔥 remove redundant position setting
farazatarodi Apr 5, 2023
0a43d62
🐛 fix broken position state for auto
farazatarodi Apr 5, 2023
02cab0b
♻️ move menu state management outside to parent component
farazatarodi Apr 5, 2023
37a9c01
💄 make border one shade lighter
farazatarodi Apr 5, 2023
fde76df
🔥 remove focus trap
farazatarodi Apr 5, 2023
b3e37d3
🔥 remove redundant ref
farazatarodi Apr 5, 2023
4ec5778
♻️ pass other props directly
farazatarodi Apr 5, 2023
1e517e0
💄 move border and shadow to the menu container
farazatarodi Apr 5, 2023
ba86dfa
💄 remove active class
farazatarodi Apr 5, 2023
a67cfe1
♻️ move border, background and padding to menu container
farazatarodi Apr 5, 2023
3340042
🔥 remove redundant check
farazatarodi Apr 5, 2023
b0e47ac
💫 add fade animation
farazatarodi Apr 6, 2023
3760fcf
🐛 use useLayoutEffect to prevent render before position calculation
farazatarodi Apr 6, 2023
c2bcc2e
♻️ move state setting to parent component
farazatarodi Apr 6, 2023
1e8ce34
♻️ set position based on the anchor element instead of the parent
farazatarodi Apr 6, 2023
07a1223
⚡️ add missing hook dependencies
farazatarodi Apr 6, 2023
b211cd3
💄 clean up styles
farazatarodi Apr 6, 2023
56ab988
🎨 rename item render function
farazatarodi Apr 6, 2023
333f6e8
✨ make menu scrollable when available space is smaller than height
farazatarodi Apr 6, 2023
34c67fc
♻️ manage Menu state in IconMenu
farazatarodi Apr 6, 2023
165c836
📝 set Menu state as active in story
farazatarodi Apr 6, 2023
916b3ea
📸 update snapshots
farazatarodi Apr 6, 2023
926b10d
Merge branch 'next-release' into FRONT-476-make-menu-scrollable
farazatarodi Apr 6, 2023
1a36b4b
📝 update change log
farazatarodi Apr 6, 2023
506b083
🩹 add a container to story to better showcase the component
farazatarodi Apr 7, 2023
56d90ed
🏷️ extract type Position
farazatarodi Apr 7, 2023
718f0e0
✨ allow position state management from the parent
farazatarodi Apr 7, 2023
a20f95e
🩹 add story container to the Menu story
farazatarodi Apr 7, 2023
f01a365
🐛 use anchor element to calculate max height
farazatarodi Apr 7, 2023
6dfc80f
🎨 revert onHide rename
farazatarodi Apr 7, 2023
2e564d5
♻️ adapt IconMenu
farazatarodi Apr 7, 2023
a753511
🐛 use focusout event on the menu element to hide
farazatarodi Apr 7, 2023
013da64
♻️ remove focusout event listener on the menu as the click handler on…
farazatarodi Apr 11, 2023
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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

### Added

- `Menu`: It is now scrollable when the available space is less than the height ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618))

### Changed

- `Container`: remove 72px on xl viewport ([@farazatarodi](https://https://github.com/farazatarodi) in [#2615](https://github.com/teamleadercrm/ui/pull/2615))
- `Container`: Removed 72px padding on xl viewport ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618))
- [BREAKING] `Menu`: State management now should happen in the parent component ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618)).
- `Menu`: Shadow and border now use the values from the design system ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618)).
- [BREAKING] `Menu`: The `onHide` prop is now called `onInactive` ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618)).
farazatarodi marked this conversation as resolved.
Show resolved Hide resolved

### Deprecated

### Removed

- [BREAKING] `Menu`: The `onShow` property is removed as the state management is now moved to the parent component ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618)).

### Fixed

- [BREAKING] `Menu`: It now requires an anchor element for positioning when it is not static. Previously it was based on the parent element, which caused layout bugs in `flex` elements ([@farazatarodi](https://https://github.com/farazatarodi) in [#2618](https://github.com/teamleadercrm/ui/pull/2618)).

### Dependency updates

## [20.1.0] - 2023-03-17
Expand Down
19 changes: 15 additions & 4 deletions src/components/menu/IconMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, ReactNode, SyntheticEvent, MouseEvent, useState } from 'react';
import React, { ReactElement, ReactNode, SyntheticEvent, MouseEvent, useState, useEffect, useRef } from 'react';
import cx from 'classnames';
import { IconMoreMediumOutline } from '@teamleader/ui-icons';
import IconButton from '../iconButton';
Expand Down Expand Up @@ -35,6 +35,9 @@ const IconMenu: GenericComponent<IconMenuProps> = ({
...others
}) => {
const [active, setActive] = useState(false);

const buttonRef = useRef<HTMLButtonElement>(null);

const buttonIcon = icon || <IconMoreMediumOutline />;
const boxProps = pickBoxProps(others);

Expand All @@ -48,17 +51,25 @@ const IconMenu: GenericComponent<IconMenuProps> = ({
onHide && onHide();
};

useEffect(() => {
if (active) {
onShow && onShow();
} else {
onHide && onHide();
}
}, [active, onHide, onShow]);

return (
<Box data-teamleader-ui="icon-menu" {...boxProps} className={cx(theme['icon-menu'], className)}>
<IconButton className={theme['icon']} icon={buttonIcon} onClick={handleButtonClick} />
<IconButton className={theme['icon']} icon={buttonIcon} onClick={handleButtonClick} ref={buttonRef} />
<Menu
active={active}
onHide={handleMenuHide}
onInactive={handleMenuHide}
onSelect={onSelect}
onShow={onShow}
position={position}
selectable={selectable}
selected={selected}
anchorElement={buttonRef.current}
>
{children}
</Menu>
Expand Down
Loading