Skip to content

feat(segment): display segment as a grid and add an ellipsis to overflowing text in a segment button - #27457

Merged
brandyscarney merged 9 commits into
feature-7.1from
FW-3401
May 24, 2023
Merged

brandyscarney merged 9 commits into
feature-7.1from
FW-3401

Conversation

@brandyscarney

@brandyscarney brandyscarney commented May 11, 2023 •

Copy link
Copy Markdown
Member

Issue number: resolves #16532


What is the current behavior?

Text that is too long to fit in a segment button does not ellipsis, instead it centers all of the text and cuts it off at the beginning and end of the text.

What is the new behavior?

Text that is wider than the segment button will now add an ellipsis and cut the text off instead of horizontally centering the text and overflowing the button (while being cut off visually).

While researching how to fix this issue I discovered that the button text was not properly overflowing when it should due to a limitation of flex. I was able to mock segments using divs and see that certain buttons were adding an ellipsis when there was room to grow. This is due to a combination of using flex-basis: 0 on the segment buttons and width: auto on the segment inside of a toolbar. This blog sums it up well, but it is not something I could work around with segment set as display: flex. When I changed the mocked segment to use display: grid, it allowed the text to properly grow, while overflowing and adding an ellipsis when it couldn't grow. This can be seen in my Codepen example.

As a result, I made the following updates:

  • Changed the ion-segment to display: grid (display: inline-grid could not be used because the highlight was not properly aligned to the bottom of a toolbar for md mode)
  • Moves the max-width for Material Design segment buttons to the parent segment by using grid-auto-columns: minmax(auto, $segment-button-md-max-width);. This is necessary for the buttons to properly center inside of the grid when they all hit the max-width (360px at the moment).
  • Sets grid-row: 1 on the host segment button. This tells the segment buttons to stay on the same row.
  • Sets max-width: 100% and overflow: hidden on the native button. This allows the text itself to ellipsis.
  • Added tests for segment wrapping & went through all existing tests to add missing ion-label elements in the segment buttons

Does this introduce a breaking change?

  • Yes
  • No

Other information

High-level changes between main and this branch

main FW-3401
main-ios branch-ios
main-md branch-md

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions Bot added package: angular @ionic/angular package package: core @ionic/core package labels May 11, 2023
@brandyscarney
brandyscarney marked this pull request as ready for review May 11, 2023 22:32
@brandyscarney
brandyscarney requested a review from a team as a code owner May 11, 2023 22:32
@averyrousseau
averyrousseau self-requested a review May 12, 2023 17:59
@brandyscarney
brandyscarney marked this pull request as draft May 17, 2023 16:49
@brandyscarney brandyscarney changed the title fix(segment): add an ellipsis to overflowing text in a segment button feat(segment): display segment as a grid and add an ellipsis to overflowing text in a segment button May 19, 2023
@brandyscarney
brandyscarney changed the base branch from main to feature-7.1 May 19, 2023 20:33
@brandyscarney

Copy link
Copy Markdown
Member Author

Changed the base branch to feature-7.1, it needs to be updated from main

@brandyscarney
brandyscarney marked this pull request as ready for review May 19, 2023 20:34
@brandyscarney
brandyscarney requested a review from a team May 19, 2023 20:34
@liamdebeasi

Copy link
Copy Markdown
Contributor

@brandyscarney Can you rebase off feature-7.1? The PR is showing changes unrelated to your PR.

@github-actions github-actions Bot added package: react @ionic/react package package: vue @ionic/vue package labels May 22, 2023
@brandyscarney
brandyscarney changed the base branch from feature-7.1 to main May 22, 2023 20:36
@brandyscarney
brandyscarney changed the base branch from main to feature-7.1 May 22, 2023 20:36
@brandyscarney

Copy link
Copy Markdown
Member Author

Separated the screenshots out to this PR: https://github.com/ionic-team/ionic-framework/pull/27531/files

Made this PR against feature-7.1. Requesting a re-review on this please!

@averyrousseau averyrousseau left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work!

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only noticing one (possibly) unintentional change (See below). Otherwise this is looking really great.

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great job!

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

Labels

package: angular @ionic/angular package package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: segment button does not truncate long text correctly

3 participants