Skip to content

feat: add hug layout for SegmentedControl#588

Open
aquelemiguel wants to merge 10 commits intomainfrom
dls-626
Open

feat: add hug layout for SegmentedControl#588
aquelemiguel wants to merge 10 commits intomainfrom
dls-626

Conversation

@aquelemiguel
Copy link
Copy Markdown
Contributor

@aquelemiguel aquelemiguel commented Mar 24, 2026

Closes DLS-626.

@aquelemiguel aquelemiguel self-assigned this Mar 24, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ldls Ready Ready Preview, Comment Mar 27, 2026 3:34pm
ldls-react-native Ready Ready Preview, Comment Mar 27, 2026 3:34pm

Request Review

@aquelemiguel aquelemiguel marked this pull request as ready for review March 25, 2026 13:32
@aquelemiguel aquelemiguel requested a review from a team as a code owner March 25, 2026 13:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new tabLayout option to SegmentedControl (React + React Native) to support content-hugging tabs (instead of always using equal-width tabs), and updates the pill sizing/positioning logic accordingly.

Changes:

  • Introduce tabLayout?: 'hug' | 'fixed' prop (defaulting to 'hug') in both ui-react and ui-rnative.
  • Update pill measurement/animation logic to support per-tab widths/positions in “hug” mode.
  • Update Storybook stories/sandbox examples to showcase both layouts and improve label truncation behavior.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
libs/ui-rnative/src/lib/Components/SegmentedControl/usePillLayout.ts Adds per-button layout registration + hug/fixed pill sizing logic
libs/ui-rnative/src/lib/Components/SegmentedControl/types.ts Adds tabLayout prop typing/docs
libs/ui-rnative/src/lib/Components/SegmentedControl/SegmentedControlContext.tsx Extends context with tabLayout + registerButtonLayout
libs/ui-rnative/src/lib/Components/SegmentedControl/SegmentedControl.tsx Wires tabLayout through, updates styles, registers button layouts, truncates labels
libs/ui-rnative/src/lib/Components/SegmentedControl/SegmentedControl.stories.tsx Adds controls + “TabLayoutShowcase” story and updates examples
libs/ui-react/src/lib/Components/SegmentedControl/usePillElementLayoutEffect.ts Switches pill layout computation to use actual button dimensions + adds “ready” gate for transitions
libs/ui-react/src/lib/Components/SegmentedControl/types.ts Adds tabLayout prop typing/docs
libs/ui-react/src/lib/Components/SegmentedControl/SegmentedControlContext.tsx Extends context with tabLayout
libs/ui-react/src/lib/Components/SegmentedControl/SegmentedControl.tsx Adds tabLayout styling and pill transition gating
libs/ui-react/src/lib/Components/SegmentedControl/SegmentedControl.stories.tsx Adds controls + “TabLayoutShowcase” story and updates examples
libs/ui-react/.storybook/components/CustomTabs.tsx Removes forced width so tabs can hug by default
apps/app-sandbox-rnative/src/app/blocks/SegmentedControls.tsx Adds examples for hug/fixed and icons
.nx/version-plans/version-plan-1774370344465-rnative.md Patch version plan for rnative
.nx/version-plans/version-plan-1774370344465-react.md Patch version plan for react

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

className,
disabled: disabledProp,
appearance = 'background',
tabLayout = 'hug',
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

Defaulting tabLayout to 'hug' changes the SegmentedControl's default sizing behavior (previously full-width equal segments). If this is meant to be non-breaking, consider keeping the existing default ('fixed') and letting consumers opt into 'hug'.

Suggested change
tabLayout = 'hug',
tabLayout = 'fixed',

Copilot uses AI. Check for mistakes.
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.

@aammami-ledger @gamegee @zel-kass This is nicely raised by Copilot, do we want to default to "fixed" as it was before to not introduce a breaking change?

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.

hmm good point, I believe hug makes more sense as a default
From what I see in the ledger-live codebase, the component seems to not be used yet

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.

I would say no as we saw the "normal" behaviour of segmented controls in other DS it's hug
But maybe validated that with Laurine as well

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.

Ty, both. I'll then ask Laurine and tag as breaking change or not according to the answer.

* - "fixed": all tabs share equal width, filling the container
* @default 'hug'
*/
tabLayout?: 'hug' | 'fixed';
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.

i have a similar question to Simon about the usage of hug in his PR would love to know your take on this #587 (comment)

I personally think we should go with fit and streamline this in Dialog to use fit as well.
But also would be happy to leave hug if you guys are in favour of that

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.

I prefer the "fit" keyword as well, I think it's more widely used. Perhaps I can update here and then we'd open a breaking change ticket for updating dialog as well?

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.

I did used the hug as well, I would suggest to move all hug to fit in a single release wdyt ?

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.

I vote for this as well, curious to know what Sim thinks

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.

Okay, will keep hug and create ticket to migrate to fit.

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 doesn’t really make sense to release two components and then introduce a breaking change right afterward—I don’t think that’s necessary, IMHO

Copy link
Copy Markdown
Collaborator

@gamegee gamegee left a comment

Choose a reason for hiding this comment

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

Minor:

I would expect the control to update the width of the Segmented control in the stories when fixed

Maybe need to set larger width to the story layout

Image

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.

4 participants