Skip to content

feat(select): flexibility in dropdown menu width#1744

Open
arina-gutuboe wants to merge 1 commit into
masterfrom
LIBS-837/select-dropdown-width-flexibility
Open

feat(select): flexibility in dropdown menu width#1744
arina-gutuboe wants to merge 1 commit into
masterfrom
LIBS-837/select-dropdown-width-flexibility

Conversation

@arina-gutuboe

@arina-gutuboe arina-gutuboe commented May 22, 2026

Copy link
Copy Markdown

Implements LIBS-837


Description

SingleSelect and MultiSelect measure the input width and pass it to the dropdown as a fixed pixel width. That works for a wide input, but breaks when the input becomes too narrow: long labels get compressed in the menu, and the result looks unnecessarily tight.

This PR adds two optional props — menuMinWidth and menuMaxWidth — on SingleSelect, MultiSelect, SingleSelectField, and MultiSelectField. They are forwarded through the shared Select / MenuWrapper stack.

image

Known issues

With only menuMinWidth (no menuMaxWidth), the menu can grow without an upper bound for very long option labels; menuMinWidth and menuMaxWidth should be used together when labels can vary significantly in length.


Checklist

  • API docs are generated
  • Tests were added
  • Storybook demos were added

Screenshots

menuMaxWidth is slightly greater than the width of the input, but less than the width of the options:
Screenshot 2026-05-22 at 11 37 33

with menuMinWidth:
Screenshot 2026-05-22 at 11 40 20

@arina-gutuboe arina-gutuboe requested a review from a team as a code owner May 22, 2026 09:56
@sonarqubecloud

Copy link
Copy Markdown

@dhis2-bot

Copy link
Copy Markdown
Contributor

🚀 Deployed on https://pr-1744--dhis2-ui.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify May 22, 2026 09:59 Inactive

@tomzemp tomzemp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! 🎉 (I've read through the code and tested in the aggregate data entry app).

Are we going to extend this to SimpleSingleSelect component as well? (The docs say we're planning on deprecating SingleSelect (https://github.com/dhis2/ui/blob/master/docs/docs/components/select.md?plain=1#L41) though I don't know if we've ever moved forward with that, but we seem to be using both in our apps.

We might also want to add some notes in the select documentation for this (above the notes generated from the props) to explain the behaviour.

loading: PropTypes.bool,
loadingText: PropTypes.string,
maxHeight: PropTypes.string,
/** Sets a maximum width for the dropdown menu */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these need to be defined as 'px', right? I tried for example percentages, and they did not work. If the idea is that we just use 'px', it might be good to update the description here (as it flows through into documentation for component)

const flexible = menuMinWidth || menuMaxWidth
const width = flexible ? 'fit-content' : inputWidth
const flexibleMinWidth = menuMinWidth
? `max(${inputWidth}, ${menuMinWidth})`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just curious: are we using the css calc definition here to avoid issues with taking the max() ourselves and just passing the resulting number?

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.

3 participants