Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chip] Support overflow ellipsis by default #18587

Closed
2 tasks done
rbarkhouse opened this issue Nov 26, 2019 · 11 comments · Fixed by #18708
Closed
2 tasks done

[Chip] Support overflow ellipsis by default #18587

rbarkhouse opened this issue Nov 26, 2019 · 11 comments · Fixed by #18708
Labels
component: chip This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@rbarkhouse
Copy link

rbarkhouse commented Nov 26, 2019

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

My chips might contain very long strings (e.g. "Antigonish_NOVA_SCOTIA_CANADA_A1B2C3_7b2b3b4b1b2b3ffba3b4b5cd_ZZZ"), so I would like to limit the width of the chip, and show the full text in a Tooltip.

However after setting a maxWidth, and customizing the overflow CSS, I unexpectedly see:

  • a truncated section from the middle of the string
  • no ellipsis
  • the Chip's delete button has disappeared
  chip: {
    maxWidth: 100,
    whiteSpace: "nowrap",
    overflow: "hidden",
    textOverflow: "ellipsis"
  }

chipcss

If I instead use "withStyles" and create my own StyledChip, and override the "label" portion of the styling, it is almost there, but I still don't see the ellipsis, and now I've lost the left-padding on the delete button:

const StyledChip = withStyles(theme => ({
  root: {
    maxWidth: 100
  },
  label: {
    whiteSpace: "nowrap",
    overflow: "hidden",
    textOverflow: "ellipsis"
  }
}))(Chip);

almost

Expected Behavior 🤔

By setting a maxWidth, overflow:hidden and textOverflow:ellipsis, I expected to see a narrower Chip, displaying the first x characters of the string, then an ellipsis... and the delete button should remain visible.

Steps to Reproduce 🕹

I modified the Chips example from Material-UI docs to demonstrate the issue:
https://codesandbox.io/s/material-demo-zt72h

Context 🔦

My chips might contain very long strings, so I would like to limit the width of the chip, and show the full text in a Tooltip.

Your Environment 🌎

Tech Version
Material-UI v4.7.0
React v16.12.0
Browser Chrome
TypeScript
etc.
@mbrookes mbrookes added the component: chip This is the name of the generic UI component, not the React module! label Nov 26, 2019
@gmltA
Copy link
Contributor

gmltA commented Nov 27, 2019

@rbarkhouse, working on the same thing right now. You need to set label display to inline-block for ellipsis to work properly.
image

@oliviertassinari
Copy link
Member

Display flex containers can't overflow ellipse, I believe it's a limitation of the platform.

In our case, it doesn't seem that we need the label to be a flex container, as the parent already handle vertical alignment:

diff --git a/packages/material-ui/src/Chip/Chip.js b/packages/material-ui/src/Chip/Chip.js
index 70ea4c0b6..3c5a41679 100644
--- a/packages/material-ui/src/Chip/Chip.js
+++ b/packages/material-ui/src/Chip/Chip.js
@@ -199,8 +199,6 @@ export const styles = theme => {
     },
     /* Styles applied to the label `span` element`. */
     label: {
-      display: 'flex',
-      alignItems: 'center',
       paddingLeft: 12,
       paddingRight: 12,
       whiteSpace: 'nowrap',

@mbrookes What do you think about the changes?

@mbrookes
Copy link
Member

diff --git a/packages/material-ui/src/Chip/Chip.js b/packages/material-ui/src/Chip/Chip.js
index 70ea4c0b6..3c5a41679 100644
--- a/packages/material-ui/src/Chip/Chip.js
+++ b/packages/material-ui/src/Chip/Chip.js
@@ -199,8 +199,6 @@ export const styles = theme => {
     },
     /* Styles applied to the label `span` element`. */
     label: {
-      display: 'flex',
-      alignItems: 'center',
+      overflow: 'hidden',
+      text-overflow: 'ellipsis',
       paddingLeft: 12,
       paddingRight: 12,
       whiteSpace: 'nowrap',

So that just setting max-width on root works?

@oliviertassinari

This comment has been minimized.

@oliviertassinari oliviertassinari added new feature New feature or request good first issue Great for first contributions. Enable to learn the contribution process. labels Nov 27, 2019
@mbrookes

This comment has been minimized.

@oliviertassinari oliviertassinari changed the title Problems limiting width of Chips and displaying textOverflow: 'ellipsis' [Chip] Support overflow ellipsis by default Nov 30, 2019
@oliviertassinari
Copy link
Member

@rbarkhouse Do you want to work on the changes proposed by @mbrookes?

@suliskh
Copy link
Contributor

suliskh commented Dec 3, 2019

Is there any ongoing work or PR? If no, I would be happy to contribute to this issue

@oliviertassinari
Copy link
Member

@suliskh I think that you are free to go :)

@suliskh
Copy link
Contributor

suliskh commented Dec 4, 2019

Thank you! Working on it

@oliviertassinari
Copy link
Member

@suliskh Did you make some progress?

@suliskh
Copy link
Contributor

suliskh commented Dec 6, 2019

PR #18708 submitted. It's my first PR, and it would be very kind of you if you guide me along.

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: chip This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants