Skip to content

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

Merged
kabaros merged 2 commits into
masterfrom
LIBS-837/select-dropdown-width-flexibility
Jul 20, 2026
Merged

feat(select): flexibility in dropdown menu width#1744
kabaros merged 2 commits into
masterfrom
LIBS-837/select-dropdown-width-flexibility

Conversation

@arina-gutuboe

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

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Thanks!
I updated the select documentation with the new behavior explanation and added links in the props description. Left a note about avoiding percentages too.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that’s correct, and to ensure consistent behavior in the affected components.

… and SingleSelect components

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@dhis2-bot
dhis2-bot temporarily deployed to netlify July 13, 2026 09:20 Inactive
@arina-gutuboe

arina-gutuboe commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

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.

Created LIBS-869

@kabaros kabaros left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it looks great @arina-gutuboe - just adding to Tom's point, would you be able to add the behaviour to SimpleSelect too? The "Simple" varieties make these components accessible and are the receommended way going forward - The SingleSelect is marked for deprecation: https://developers.dhis2.org/docs/ui/components/select#single-select .. we're just doing it gradually since it's used in a lot of places and there was no way to make the changes backwards compatible (I can give you more context if you'd like)

it would be good to add the same functionality to SimpleSingleSelect before merging - happy to help with that

@kabaros

kabaros commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

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.

Created LIBS-869

Sorry @arina-gutuboe , I didn't notice your comment about the linked ticket. I will merge this one, and you can catch up with the other ticket after.

@kabaros
kabaros merged commit b721f9d into master Jul 20, 2026
19 checks passed
@kabaros
kabaros deleted the LIBS-837/select-dropdown-width-flexibility branch July 20, 2026 17:04
dhis2-bot added a commit that referenced this pull request Jul 20, 2026
# [10.17.0](v10.16.5...v10.17.0) (2026-07-20)

### Features

* **select:** flexibility in dropdown menu width ([#1744](#1744)) ([b721f9d](b721f9d))
@dhis2-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 10.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants