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

Menu grid item #506

Merged
merged 23 commits into from
Feb 15, 2022
Merged

Menu grid item #506

merged 23 commits into from
Feb 15, 2022

Conversation

laviomri
Copy link
Contributor

@laviomri laviomri commented Feb 1, 2022

Added MenuGridItem
MenuGridItem demo

Basic

  • Used plop (npm run plop) to create a new component.
  • PR has description.
  • New component is functional and uses Hooks.
  • Component defines PropTypes.

Style

  • Styles are added to NewComponent.modules.scss file inside of the NewComponent folder.
  • Component uses CSS Modules.
  • Design is compatible with Monday Design System.

Storybook

  • Stories were added to /src/NewComponent/__stories__/NewComponent.stories.js file.
  • Stories include all flows of using the component.

Tests

@@ -91,12 +95,10 @@ const Menu = forwardRef(
setIsInitialSelectedState(true);
}, [setIsInitialSelectedState]);

useLayoutEffect(() => {
useEffect(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When using requestAnimationFrame, long-pressing the arrows didn't work properly with the focus/blur handlers.

Copy link
Contributor

Choose a reason for hiding this comment

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

@laviomri it looks good, but lets try to think if it is a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

theoretically, it may cause a very very short delay until the focus is actually called (since useEffect is async and useLayoutEffect is sync, basically).
In practice I've played with it quite a bit and didn't see any issue with it.. Do you have specific concerns?

Base automatically changed from feature/omri/menu-enhancements to master February 1, 2022 14:31
@laviomri laviomri requested a review from a team February 13, 2022 07:41
@@ -91,12 +95,10 @@ const Menu = forwardRef(
setIsInitialSelectedState(true);
}, [setIsInitialSelectedState]);

useLayoutEffect(() => {
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@laviomri it looks good, but lets try to think if it is a breaking change?

@@ -0,0 +1,126 @@
import { renderHook } from "@testing-library/react-hooks";
Copy link
Contributor

Choose a reason for hiding this comment

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

b e a u t i f u l l !!!

src/components/Menu/MenuGridItem/MenuGridItem.jsx Outdated Show resolved Hide resolved

export const useFocusGridItemByActiveStatus = ({ wrapperRef, childRef, index, activeItemIndex }) => {
const { lastNavigationDirectionRef } = useLastNavigationDirection();
const isActive = useMemo(() => index === activeItemIndex, [activeItemIndex, index]);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can move it into the use effect?

Copy link
Contributor Author

@laviomri laviomri Feb 14, 2022

Choose a reason for hiding this comment

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

@orrgottlieb this is intentional - the calculations of isActive may run a few times without changing the result (e.g. when index = 2 and the activeItemIndex changes from 3 to 4, and then to 0. isActive will remain false all the time). I want the content of the useEffect to run ONLY when the isActive actually changes, not when the calculation is performed.

onOutboundNavigation: (elementRef, direction) => {
innerKeyboardContext.onOutboundNavigation(elementRef, direction);

switch (direction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

no right because of sub menus ? - i guess we don't allow sub menu and a MenuItemGrid

Copy link
Contributor Author

@laviomri laviomri Feb 14, 2022

Choose a reason for hiding this comment

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

@orrgottlieb if we would have supported submenus inside a MenuGridItem, then we should have added a handler for outbound right navigation... however, I don't think such behavior makes any sense (I mean, it will be a grid that opens a sub menu when navigating to the right of it. Sounds odd, no? 🤔 ).
In any case, if we'll migrate the Menu implementation to use the grid keyboard navigation, it will be easier to support such (odd) behaviors 😄

@@ -75,3 +75,4 @@ export { default as ColorUtils } from "../utils/colors-utils";
export { default as Slider } from "./Slider/Slider";
export { default as IconButton } from "./IconButton/IconButton";
export { default as Flex } from "./Flex/Flex";
export { default as MenuGridItem } from "./Menu/MenuGridItem/MenuGridItem";
Copy link
Contributor

Choose a reason for hiding this comment

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

please add to publish components as well

Copy link
Contributor Author

@laviomri laviomri Feb 14, 2022

Choose a reason for hiding this comment

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

@orrgottlieb I'm not sure I understand the usage of each file correctly..
Also, should I add useGridKeyboardNavigation to the end of published-components as well? (EDIT: I've added it for now)

@laviomri laviomri merged commit ba23d10 into master Feb 15, 2022
@laviomri laviomri deleted the feature/omri/menu-grid-item branch February 15, 2022 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants