-
Notifications
You must be signed in to change notification settings - Fork 317
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
Menu grid item #506
Conversation
…nnecessary rerenders
@@ -91,12 +95,10 @@ const Menu = forwardRef( | |||
setIsInitialSelectedState(true); | |||
}, [setIsInitialSelectedState]); | |||
|
|||
useLayoutEffect(() => { | |||
useEffect(() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
…to feature/omri/menu-enhancements
…/monday-ui-react-core into feature/omri/menu-grid-item
…to feature/omri/menu-grid-item
…to feature/omri/menu-grid-item
@@ -91,12 +95,10 @@ const Menu = forwardRef( | |||
setIsInitialSelectedState(true); | |||
}, [setIsInitialSelectedState]); | |||
|
|||
useLayoutEffect(() => { | |||
useEffect(() => { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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 !!!
|
||
export const useFocusGridItemByActiveStatus = ({ wrapperRef, childRef, index, activeItemIndex }) => { | ||
const { lastNavigationDirectionRef } = useLastNavigationDirection(); | ||
const isActive = useMemo(() => index === activeItemIndex, [activeItemIndex, index]); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
Added
MenuGridItem
Basic
npm run plop
) to create a new component.PropTypes
.Style
NewComponent.modules.scss
file inside of theNewComponent
folder.Storybook
/src/NewComponent/__stories__/NewComponent.stories.js
file.Tests