-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(chips): Handle leading/trailing icon styles #2191
Changes from 19 commits
5050824
22d0394
6f34c1d
5c3365a
a57a437
9a3b946
152a9d5
b2fc5b4
27165d9
52a8254
28205ee
7a411ef
33fa00d
72dbc4c
23d3930
93fc133
a3e4d59
88fce91
0f91516
200638f
2a4f687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,25 +40,52 @@ npm install --save @material/chips | |
|
||
```html | ||
<div class="mdc-chip-set"> | ||
<div class="mdc-chip"> | ||
<div class="mdc-chip" tabindex="0"> | ||
<div class="mdc-chip__text">Chip content</div> | ||
</div> | ||
<div class="mdc-chip"> | ||
<div class="mdc-chip" tabindex="0"> | ||
<div class="mdc-chip__text">Chip content</div> | ||
</div> | ||
<div class="mdc-chip"> | ||
<div class="mdc-chip" tabindex="0"> | ||
<div class="mdc-chip__text">Chip content</div> | ||
</div> | ||
</div> | ||
``` | ||
|
||
#### Leading and Trailing Icons | ||
|
||
You can optionally add a leading icon (i.e. thumbnail) and/or a trailing icon to a chip. To add an icon, add an `i` element with your preferred icon, give it a class of `mdc-chip__icon`, and a class of either `mdc-chip__icon--leading` or `mdc-chip__icon--trailing`. If you're adding a trailing icon, also set `tabindex="0"` and `role="button"` to make it accessible by keyboard and screenreader. | ||
|
||
##### Leading icon | ||
|
||
```html | ||
<div class="mdc-chip mdc-chip"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like chips too, but 2 is probably too much here 😉 |
||
<i class="material-icons mdc-chip__icon mdc-chip__icon--leading">event</i> | ||
<div class="mdc-chip__text">Add to calendar</div> | ||
</div> | ||
``` | ||
|
||
##### Trailing icon | ||
|
||
```html | ||
<div class="mdc-chip mdc-chip"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
<div class="mdc-chip__text">Jane Smith</div> | ||
<i class="material-icons mdc-chip__icon mdc-chip__icon--trailing" tabindex="0" role="button">cancel</i> | ||
</div> | ||
``` | ||
|
||
### CSS Classes | ||
|
||
CSS Class | Description | ||
--- | --- | ||
`mdc-chip-set` | Mandatory. Indicates the set that the chip belongs to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change It will give us much better control over spacing, so we can match the spec exactly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put it in #2265 since it requires the creation of a new file (mdc-chip-set/mdc-chip-set.scss) |
||
`mdc-chip` | Mandatory. | ||
`mdc-chip__text` | Mandatory. Indicates the text content of the chip. | ||
`mdc-chip-set` | Mandatory. Indicates the set that the chip belongs to. | ||
`mdc-chip__text` | Mandatory. Indicates the text content of the chip | ||
`mdc-chip__icon` | Optional. Indicates an icon in the chip | ||
`mdc-chip__icon--leading` | Optional. Indicates a leading icon in the chip | ||
`mdc-chip__icon--trailing` | Optional. Indicates a trailing icon in the chip | ||
|
||
> _NOTE_: Every element that has an `mdc-chip__icon` class must also have either the `mdc-chip__icon--leading` or `mdc-chip__icon--trailing` class. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay! This seems much more intuitive to me 😀 |
||
|
||
### Sass Mixins | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,50 @@ | |
@include mdc-ripple-radius-bounded; | ||
@include mdc-chip-corner-radius($mdc-chip-border-radius-default); | ||
@include mdc-chip-fill-color($mdc-chip-fill-color-default); | ||
@include mdc-chip-ink-color($mdc-chip-ink-color-default); | ||
@include mdc-chip-ink-color(text-primary-on-light); | ||
|
||
display: inline-block; | ||
margin: 5px; | ||
display: inline-flex; | ||
align-items: center; | ||
margin: 4px; | ||
padding: $mdc-chip-vertical-padding $mdc-chip-horizontal-padding; | ||
cursor: pointer; | ||
outline: none; | ||
overflow: hidden; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest using Then, instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks for the tip! |
||
|
||
.mdc-chip__text { | ||
display: inline-block; | ||
vertical-align: middle; | ||
// Set line-height to be <18px to force the content height of mdc-chip to be 18px. | ||
line-height: 17px; | ||
} | ||
|
||
.mdc-chip__icon { | ||
color: $mdc-chip-icon-color; | ||
vertical-align: middle; | ||
border-radius: 50%; | ||
outline: none; | ||
} | ||
|
||
.mdc-chip__icon--leading { | ||
margin: -4px 4px -4px -4px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awwwww yeeeeeeaaaaaa |
||
} | ||
|
||
.mdc-chip__icon--trailing { | ||
margin: 0 -4px 0 4px; | ||
|
||
&:hover { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we normally put a blank line before I was going to suggest adding a stylelint setting to catch this in the future, but I can't seem to find one for it 🙁 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newline before this block? (Kinda surprised lint doesn't complain?) |
||
color: $mdc-chip-trailing-icon-hover-color; | ||
} | ||
|
||
&:focus { | ||
color: $mdc-chip-trailing-icon-focus-color; | ||
} | ||
} | ||
|
||
// This overrides styles defined in the .material-icons CSS class | ||
// which is loaded separately, so the order of CSS definitions is not | ||
// guaranteed. Therefore, increase specifity to ensure overrides apply. | ||
.mdc-chip__icon.mdc-chip__icon--trailing { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment to the effect of:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment indicating these are more specific to ensure they override icon styles in other libraries e.g. material-icons (like in https://github.com/material-components/material-components-web/pull/2242/files) |
||
width: $mdc-chip-trailing-icon-size; | ||
height: $mdc-chip-trailing-icon-size; | ||
font-size: $mdc-chip-trailing-icon-size; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've given the trailing icons
role
, but what about chips themselves? (I forget if that's being handled in #2215)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @bonniezhou decided to do most of the a11y stuff (or the tricky parts that require JS, anyway) in a separate follow up PR, cuz shoehorning it into this one was getting kinda hairy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's tracked in #2259. Also, design confirmed that we should add a
role
but looking into options other thanbutton
(maybemenuitem
or something similar).