patternfly / patternfly-react

A set of React components for the PatternFly project.
https://react-staging.patternfly.org/
MIT License
796 stars 356 forks source link

Select with description - how to include description in SelectToggle? #7522

Closed cben closed 2 years ago

cben commented 2 years ago

Is this a new component or an extension of an existing one? Existing <Select> component, with <SelectOption> showing secondary description rows.

Describe the feature When the Select isOpen, each option can show 2 rows: value + description.
But the SelectToggle header only shows the selected value, no description. Depending on how values vs descriptions were used, this may be hiding important information, especially when the dropdown is closed.

More generally, it's useful to control how an option shows in SelectToggle separately from how it shows in SelectOption.

Are there visuals for this feature? If applicable, please include examples for each state and for varying widths

Use case: In OpenShift Cluster Manager when choosing cloud machine types, we put human-friendly details like CPUs and RAM size into the more prominent value and the low-level instance id into the description. But the low-level ids are meaningful to some users and our design wants to display them when the dropdown is closed. This is the desired behavior: machine_types_with_id_AWS

Alternative styles e.g. showing the description in a smaller 2nd line inside SelectToggle would also be OK.

I'm not sure whether this makes sense to enable automatically when descriptions are present. Besides backwards-compatibility concern, I think it does depend on specific use case.

Any other information?

The docs are unclear how to achieve this.

If API extension is desired, perhaps SelectOptionObject interface should be extended with an optional method to control how SelectToggle shows it?

mcoker commented 2 years ago

Hey @cben, as an interim solution, you could wire this up by also including the description as a child of <SelectOption> and hiding it via CSS when it's in the select menu - https://codesandbox.io/s/stoic-montalcini-z3cfg8?file=/style.css

mcarrano commented 2 years ago

Upon some discussion with @shirimordechay a different alternative might be to do something like this:

image (5)

@mcoker @nicolethoen @tlabaj I'm wondering what kind of flexibility we have for customizing menu items and reflecting that in the toggle. For example, I'm wondering if we can leverage some of the techniques demonstrated in this example: https://www.patternfly.org/v4/components/select#multiple-with-custom-objects Thoughts?

nicolethoen commented 2 years ago

@mcarrano The Select component in its current implementation does not have very much flexibility on the contents on the toggle. But if a MenuToggle and Menu is used to build something that looks like a Select, then you'd have more flexibility.

The MenuToggle, as it's implemented now, does not have styles for 'description text' below the Toggle's primary text. However, it could be used to display more info as is done in the screenshot you included

mcarrano commented 2 years ago

@cben After discussing this more with the team, it seems like the best path forward is for you to build this using our new Menu and Menu toggle components that will give you more flexibility (as opposed to the Select component). You can see some examples of how to use that here: https://www.patternfly.org/v4/demos/composable-menu. If you reach out to us on Slack we'd be glad to help you with any customization you may need.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.