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

feat(@clayui/drop-down): LPD-47559 Cascading Menu should turn into dr… #5962

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pat270
Copy link
Member

@pat270 pat270 commented Mar 11, 2025

…illdown in smaller screens

https://liferay.atlassian.net/browse/LPD-47559

I was running into errors returning drilldown when resizing. This PR renders Drilldown if the window width is < 768px and cascade at larger sizes. I also couldn't figure out how to add dropdown-menu-indicator-start on dropdown-menu based on if an item had an icon on the left side in Drilldown.

cascadetodrilldown

@ethib137
Copy link
Member

Thanks @pat270 ... so what still needs to be fixed on this one? The screenshot shows the icon overlapping the text of an item, but what else is still not working?

@pat270
Copy link
Member Author

pat270 commented Mar 12, 2025

@ethib137 I think I figured out a way to get the icon to work. The other thing that's not working, if needed, is that it doesn't convert to drilldown or cascading menu when resizing the window. It just renders drilldown or cascading menu depending on the starting window width.

Copy link
Member

@matuzalemsteles matuzalemsteles left a comment

Choose a reason for hiding this comment

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

I believe this is a more complex task than it seems, the DropDownWithItems component has more features than DropDownWithDrilldown, so it wouldn't be just a matter of mapping the items to the Drilldown data structure, it would be necessary to refactor the component and add support for all types, ideally making it so that both components can reuse code to avoid duplication and complexity.

So this requires more work here and going with this may break the DropDownWithItems component when rendered on a smaller screen. Another strategy would be to implement drilldown only for the case when the type is contextual.

ref(node);
const defaultActiveMenu = useId();

const windowWidth = window.innerWidth;
Copy link
Member

Choose a reason for hiding this comment

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

You can use our useIsMobileDevice hook in @clayui/shared for this. One thing to note is that when the user resizes the screen this value does not change so we would have to add an event to update this value whenever it is resized. We can do this in the hook with a throttle if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Since @pat270 is on PTO, I am working on this fix

Copy link
Member

Choose a reason for hiding this comment

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

@matuzalemsteles, I've implemented the fix, but I ran into some issues due to the way hooks render. Since hooks can't be called inside an if statement and useId() relies on useMemo, I worked around it by adding a separate ID specifically for the drilldown.

Do you have any suggestions for a different approach?

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

@ilzamcmed I'll take a look at this. The ideal is to have a unique ID per instance because we can have several components rendered on the page and this will have the same ID.

@matuzalemsteles
Copy link
Member

I'm going to work on it now, we need to rewrite some parts of the component, ideally we should refactor both components but this can take a long time so I'll try to add some new rules to the cascading menu to have the same behavior as the drilldown.

@ilzamcmed
Copy link
Member

Thanks @matuzalemsteles!
Let me know if I can help on anything.

…wn and compatibility with the DropDownWithItems component
@matuzalemsteles
Copy link
Member

Well, commit refactoring the Drilldown and DropDownWithItems components, now both components render the same items for compatibility and also support almost the same props. It is now safe to use Drilldown in DropDownWithItems when on a mobile version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants