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.

Move selected icon position in MenuOptionGroup

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

I want to be able to put the checkmark icon to the right of the option item option

Describe the solution you’d like

We could add a iconPosition prop like this

<MenuOptionGroup defaultValue="asc" title="Order" type="radio" iconPosition="right">
      <MenuItemOption value="asc">Ascending</MenuItemOption>
      <MenuItemOption value="desc">Descending</MenuItemOption>
 </MenuOptionGroup>

or we could make the checkmark into its own component and we would use it like this

<MenuOptionGroup defaultValue="asc" title="Order" type="radio">
      <MenuItemOption value="asc">Ascending<MenuItemOption.Checkmark/></MenuItemOption>
      <MenuItemOption value="desc">Descending<MenuItemOption.Checkmark/></MenuItemOption>
 </MenuOptionGroup>

or we could make a leftSelectedIcon and rightSelectedIcon prop

<MenuOptionGroup defaultValue="asc" title="Order" type="radio" rightSelectedIcon={<CheckmarkIcon/>}>
      <MenuItemOption value="asc">Ascending</MenuItemOption>
      <MenuItemOption value="desc">Descending</MenuItemOption>
 </MenuOptionGroup>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
with-heartcommented, Dec 27, 2020

Yeah, I think we should add this functionality. Shouldn’t be a huge change.

1reaction
ljosberinncommented, Sep 15, 2020

Sounds like a good idea - currently the right side is not used: https://github.com/chakra-ui/chakra-ui/blob/develop/packages/menu/src/menu.tsx#L271

I guess we can follow the example of Button and replace icon and iconSpacing with leftIcon and rightIcon + their corresponding spacing. The complexity would barely increase.

Downside:

  • 0.75rem less width for content
  • breaking change for MenuItemOption

Something like:

// omitted forwardRef here for readability
export const MenuItemOption = function MenuItemOption(props, ref) {
  const {
    leftIcon = <CheckIcon />,
    leftIconSpacing = "0.75rem",
    rightIcon,
    rightIconSpacing = "0.75rem",
    ...htmlProps
  } = props;

  const ownProps = useMenuOption(htmlProps);
  const ownRef = mergeRefs(ownProps.ref, ref);

  const visibility = props.isChecked ? "visible" : "hidden";

  return (
    <StyledMenuItem {...ownProps} ref={ownRef}>
      <MenuIcon fontSize="0.8em" mr={leftIconSpacing} visibility={visibility}>
        {leftIcon}
      </MenuIcon>

      <chakra.span flex="1">{ownProps.children}</chakra.span>

      <MenuIcon fontSize="0.8em" ml={rightIconSpacing} visibility={visibility}>
        {rightIcon}
      </MenuIcon>
    </StyledMenuItem>
  );
};

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - How to increase icon position if item is selected in ...
What I am trying to accomplish is basically having the icon move up a little bit when the icon is selected and move...
Read more >
Menu - Chakra UI
MenuItem : The trigger that handles menu selection. Must be a direct child of a MenuList . MenuGroup : A wrapper to group...
Read more >
Menu - Purity UI Dashboard - Creative Tim
MenuItem : The trigger that handles menu selection. Must be a direct child of a MenuList . MenuGroup : A wrapper to group...
Read more >
MOVE GALLERY WHEN I SELECT A ICON
There is a way to move a label and a gallery to move the X and Y? I like to remove this space...
Read more >
Menu - Chakra UI
MenuItem : The trigger that handles menu selection. ... MenuOptionGroup : A wrapper for checkable menu items (radio and checkbox).
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