question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

šŸ’” Proposal - dropdown refactoring

See original GitHub issue

Forma 36 contribution proposal

The problem

At the moment we have variety of implementation with dropdown within different apps. They are not consistent, do not pass a11y rules, and hard to maintain because of custom complex logic. The list of examples of current Dropdown usage:

  1. Two places where we create custom MultiSelect component based on Dropdown:

Screen Shot 2021-08-20 at 17 04 19

  1. Two places where we changing default click event as a trigger to hover:

Screen Shot 2021-08-20 at 17 05 40

  1. Several places where we use DropdownList without Dropdown, and CardActions without Card components:

Screen Shot 2021-08-20 at 17 07 00

  1. Places where we use Dropdown as a select:

Screen Shot 2021-08-20 at 17 07 42

  1. There are some places where we can put all sort of content inside dropdown:

Screen Shot 2021-08-20 at 17 08 36

Other interesting things:

  1. In 90% of the use cases we repeat the same simple logic to open/close a dropdown when triggerElem clicked. Sometimes there are additional callback passed, like here. Maybe itā€™s worth to make component uncontrolled by default?

  2. Place where we use span as a trigger element: span

The proposed solution

  1. Do a base component, Dropdown or Popover (popover is a more common name based on other popular components libraries).

    • Component should be also exposed, since it will be used as a one for a custom content. So it will just trap focus inside dropdown, when itā€™s opened, and use default tab navigation within its content (focusTrapping should be optional prop).
    • Trigger element should be wrapped and passed as one of the children, not as a prop. It will introduce more flexibility for the trigger element and we will not have such cases, when the props that we pass on toggleElement end up on the wrong element. Example:
    // current
    <Dropdown toggleElement={<Button>Toggle<Button/>}>
    <DropdownContent>{...}</DropdownContent>
    </Dropdown>
    
    // new proposal
    <Dropdown>
    <DropdownTrigger><Button>Toggle<Button/><DropdownTrigger/>
    
    <DropdownContent>{...}</DropdownContent>
    </Dropdown>
    
  2. Based on prev basic component we will create more specific one:

  3. I would argue that we need also Select component based on Dropdown. With clear design/usage guidance. We will probably use mostly Menu component or our native Select (from forms elements).

  4. Make Menu component uncontrolled by default. So no need to repeat the same logic of togling by click. And also less temptation to introduce some custom logic, like open on hover.

  5. For Menu and Autocomplete (and Select if we decided to do it) components make default behaviour where dropdown close itself when option clicked/chosen. Since itā€™s a recommended behaviour by w3c and I already found this approach in couple of places in our codebase example

  6. If it possible, we can also expose the logic with keyboard navigation through menu items as a hook. So when someone needs to do some very custom menu they can use raw Dropdown and our hook for custom menu list.

  7. Since I didnā€™t find any usage of dropdown nested menus in out projects, I think we can drop support of it.

Additionally

We also have some inconvenient behaviour with dropdown in the iframe. For example when we use dropdown in our entry field iframe, the iframe does not adapt to the open dropdown height. field_editor So I propose to add specific data attribute on our dropdown and add this code to updateHeight method. We can also add this attribute for others absolute positioned element that we want to be counted. So itā€™s not limited only to the dropdowns.


SO WDYT? šŸ¤”

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
thebessoncommented, Aug 9, 2021

Thanks, @bgutsol, I understand now! You are right, I agree on this one too.

1reaction
bgutsolcommented, Aug 9, 2021

awesome, very in-depth research! I have one question regarding this point:

  1. I would argue that we need also Select component based on Dropdown. With clear design/usage guidance. We will probably use mostly Menu component or our native Select (from forms elements).

It is a bit unclear for me from the wording, do you propose to just make a Select based on this base component Popover and also keep native select from form components?

Thanks @thebesson

Sorry for the bad wording. I meant that that we probably donā€™t have to create a Select component that will be based on the popover. Because the cases that we have in the 4th example can be covered with Menu component or with our native select from form components. As @gui-santos said itā€™s just the matter of better guidelines and documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

šŸ’” Proposal - components documentation in README Ā· Issue #659 ...
Hey! For the overview purposes I will add the list of the components that needs README.mdx. We would like to have consistent docs,...
Read more >
Replace bootstrap dropdown in app/views/shared/issuable/form/_ ...
Replace bootstrap dropdown in app/views/shared/issuable/form/_type_selector.html.haml. We're in the process of migrating away all uses of Bootstrap.
Read more >
Code Refactoring Best Practices: When (and When Not) to Do It
Code refactoring is a process used in the DevOps philosophy that involves editing and cleaning up previously written code without changingĀ ...
Read more >
Explicit exceptions - šŸ’” Ideas
Update: There's a proposal repo out now over here that explains in-depth where ... It's very easy to refactor your higher-level code without...
Read more >
Documentation - Repositories Page - P42
Takes you to the Install P42.ai page to select the GitHub account you want to ... šŸ’” If you see the "Repository too...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found