Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(text-field): Add support for leading/trailing icons at the same time #3451

Merged
merged 27 commits into from
Sep 12, 2018

Conversation

williamernest
Copy link
Contributor

fixes: #3302

@williamernest williamernest force-pushed the fix/text-field/both-icons branch from a536d33 to 8b80f1c Compare August 28, 2018 23:58
@GusRuss89
Copy link

Once this is merged will it also pave the way for leading icons on select fields? The spec says nothing about not supporting icons on select fields as far as I can see...

@williamernest
Copy link
Contributor Author

@GusRuss89 Yes. The goal is to add support for leading icons and invalid styles to the current native select. We're also adding an enhanced select with the menu component that should also have feature parity with the text field.

@porfirioribeiro
Copy link

porfirioribeiro commented Sep 3, 2018

@williamernest That would be great to have also!

Native selects are cool, but with not much control
Currently doing a React select for my app wrapping up a TextField

@@ -382,6 +382,14 @@
@include mdc-text-field-icon-horizontal-position_(right, $mdc-text-field-dense-icon-position, $mdc-text-field-dense-icon-padding);
}

@mixin mdc-text-field-with-both-icons_ {
@include mdc-text-field-icon-horizontal-position-two-icons_($mdc-text-field-icon-position, $mdc-text-field-icon-padding, $mdc-text-field-trailing-icon-position,$mdc-text-field-icon-padding);
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing space after last comma

@@ -42,11 +42,11 @@ const icon = new MDCTextFieldIcon(document.querySelector('.mdc-text-field-icon')
```
## Variants

Leading and trailing icons can be applied to text fields styled as `mdc-text-field--box` or `mdc-text-field--outlined`. To add an icon, add the relevant class (either `mdc-text-field--with-leading-icon` or `mdc-text-field--with-trailing-icon`) to the root element, add an `i` element with your preferred icon, and give it a class of `mdc-text-field__icon`.
Leading and trailing icons can be applied to text fields styled as the default or `mdc-text-field--outlined`. To add an icon, add the relevant class (either `mdc-text-field--with-leading-icon` and/or `mdc-text-field--with-trailing-icon`) to the root element, add an `i` element with your preferred icon, and give it a class of `mdc-text-field__icon`. If using 2 icons, the first icon will be positioned before the input text, and the second icon will be positioned after.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove "either" from the parenthetical

Also... in reading the last sentence... is this supposed to be a "will", or a "must"? Like, is this talking about how the markup is supposed to be arranged?

.mdc-text-field__icon {
@include mdc-theme-prop(color, $color);
&:first-of-type {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just pointing out this will only work as long as it's safe to assume that the icons always use a distinct type (e.g. i, svg, etc., not div), since first-of-type and last-of-type apply against the element type, not the selector. I think this is a safe assumption...

Choose a reason for hiding this comment

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

Maybe add a class like mdc-text-field__icon--leading and mdc-text-field__icon--trailing can prevent that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can work around the last-of-type issue using a sibling selector

.mdc-text-field__icon ~ .mdc-text-field__icon {
    color: red;
}

@@ -22,9 +22,9 @@

// Public mixins

@mixin mdc-text-field-icon-color($color) {
@mixin mdc-text-field-icon-color($color, $onlyTrailing: false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why we're singling out trailing like this?

Would it make more sense to have there be 2 color parameters? i.e. $color, $trailingColor: $color where if you specify one it applies to both, but if you specify two they apply to leading/trailing?

(Could also do $trailingColor: null and still conditionalize the output like you're currently doing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was only used to style the trailing icon when in an invalid state, since that's the only time the 2 icons have different colors. I don't think it makes sense to support passing in 2 colors, since majority of the time the icons will always be the same color. There's only 1 time we need an exception (and to be honest, I'm not sure why leading icons don't turn red when the text field is invalid).

@kfranqueiro
Copy link
Contributor

This looks OK from a styling perspective, but I think there are things on the JS side that this isn't taking into account...

The leading/trailing icon also has a controller/foundation, and text field is currently still assuming that there's only ever one of them to manage. This affects a few things:

  • When the text field is set enabled/disabled, that is passed down to the icon foundation to remove its tabindex if it has one. (It properly remembers its previous tabindex and restores it when it is enabled again.)
  • There are APIs on the top-level text-field component and foundation which forward to setting the icon's aria-label and content; these are sometimes used to swap between 2 icons.

@codecov-io
Copy link

codecov-io commented Sep 5, 2018

Codecov Report

Merging #3451 into master will decrease coverage by 0.01%.
The diff coverage is 97.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3451      +/-   ##
==========================================
- Coverage   98.41%   98.39%   -0.02%     
==========================================
  Files         120      120              
  Lines        5036     5058      +22     
  Branches      620      627       +7     
==========================================
+ Hits         4956     4977      +21     
- Misses         80       81       +1
Impacted Files Coverage Δ
packages/mdc-textfield/constants.js 100% <ø> (ø) ⬆️
packages/mdc-textfield/foundation.js 98.97% <100%> (+0.04%) ⬆️
packages/mdc-textfield/index.js 93.67% <95.83%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b6370d...289905e. Read the comment docs.

@kfranqueiro kfranqueiro changed the title fix(text-field): Add support for leading/trailing icons at the same time feat(text-field): Add support for leading/trailing icons at the same time Sep 7, 2018
Copy link
Contributor

@kfranqueiro kfranqueiro left a comment

Choose a reason for hiding this comment

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

Screenshot tests are showing diffs in the error state pages for trailing icons - the icons are no longer red, and I'm not sure this is an intentional/correct change...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MDCTextField: Leading and trailing icons do not render properly when used at the same time
8 participants