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

[TextField] add floatingLabelFocusStyle prop #4043

Merged

Conversation

echenley
Copy link
Contributor

@echenley echenley commented Apr 19, 2016

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

@echenley echenley changed the title [TextField] adds floatingLabelFocusStyle prop [TextField] add floatingLabelFocusStyle prop Apr 19, 2016

describe('<TextFieldLabel>', () => {
it('uses focus styles', () => {
const component = shallow(
Copy link
Member

Choose a reason for hiding this comment

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

Can you use wrapper instead of component?

@oliviertassinari oliviertassinari added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Apr 20, 2016
@echenley
Copy link
Contributor Author

echenley commented Apr 20, 2016

Updates made. Let me know if there's anything else!

@oliviertassinari oliviertassinari added PR: Review Accepted PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Apr 22, 2016
@oliviertassinari
Copy link
Member

@echenley That looks good to me. Could you squash down and rebase? Thanks.

@echenley echenley force-pushed the feature/floatingLabelFocusStyle branch 2 times, most recently from f28bdf1 to 8904c37 Compare April 24, 2016 20:45
@echenley
Copy link
Contributor Author

@oliviertassinari Should be good to go. Thank you!

* The style object to use to override floating label styles when focused.
*/
floatingLabelFocusStyle: PropTypes.object,

Copy link
Member

Choose a reason for hiding this comment

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

Could you remove this line cf. #4073 😁?

@oliviertassinari oliviertassinari removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 24, 2016
@echenley echenley force-pushed the feature/floatingLabelFocusStyle branch from 8904c37 to 027c96d Compare April 24, 2016 21:04
@oliviertassinari
Copy link
Member

@nathanmarks Feel free to merge if you are happy with this PR.

pointerEvents: 'none',
}, props.shrinkStyle) : null;

return Object.assign({
Copy link
Member

Choose a reason for hiding this comment

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

@oliviertassinari should we enforce the styles.root convention here?

Copy link
Member

Choose a reason for hiding this comment

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

@nathanmarks I would say yes 👍.

@echenley echenley force-pushed the feature/floatingLabelFocusStyle branch from 027c96d to bd92715 Compare April 24, 2016 21:36
@echenley
Copy link
Contributor Author

Updated:

  • sort TextFieldLabel props alphabetically
  • use styles.root pattern

cursor: props.disabled ? 'default' : 'text',
transform: 'scale(1) translate3d(0, 0, 0)',
transformOrigin: 'left top',
pointerEvents: 'auto',
Copy link
Member

@nathanmarks nathanmarks Apr 24, 2016

Choose a reason for hiding this comment

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

Can we remove pointerEvents: 'none', out of the TextField.js~getStyles().floatingLabel object? seems like the default is already enforced here. (here being in the getStyles() function as a whole, not this line)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Member

Choose a reason for hiding this comment

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

(do correct me if I'm wrong though!)

Copy link
Contributor Author

@echenley echenley Apr 24, 2016

Choose a reason for hiding this comment

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

You're right, it was redundant. I wonder if it might be better to just move the defaultStyles in TextFieldLabel to styles.floatingLabel in TextField instead of the other way? That would remove one object merge from the mix. I'll make a commit to show what I mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See f8a4a63.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it might be better to just move the defaultStyles in TextFieldLabel to styles.floatingLabel in TextField instead of the other way?

The idea is to make each component independent. I think that we shouldn't move the style to the parent component.

@echenley echenley force-pushed the feature/floatingLabelFocusStyle branch from bd92715 to b800fe1 Compare April 24, 2016 21:45
@nathanmarks
Copy link
Member

@oliviertassinari TextFieldUnderline accesses muiTheme itself to set defaults for the component: https://github.com/callemall/material-ui/blob/master/src/TextField/TextFieldUnderline.js#L64 Whereas TextField sets the defaults for TextFieldLabel. I think these should be consistent with each other.

@nathanmarks
Copy link
Member

The TextFieldLabel may as well access the theme variables itself for the colour in order to set those 2 defaults currently passed in by TextField.

@oliviertassinari
Copy link
Member

@nathanmarks I agree 👍. Let's remove the color: hintColor, from the TextField.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 24, 2016

@nathanmarks Humm, I'm not sure though. There is like 10 lines of logic to update the color after behing set.

@nathanmarks
Copy link
Member

@oliviertassinari bleh, that's annoying.

@oliviertassinari
Copy link
Member

@echenley Could you remove the second commit? Let's try to keep separate our concerns.

@nathanmarks
Copy link
Member

nathanmarks commented Apr 24, 2016

I guess it just feels strange because it is an escape hatch by design through to the component during the focus state of the input the parent contains (these types of props).

@echenley echenley force-pushed the feature/floatingLabelFocusStyle branch from f8a4a63 to b800fe1 Compare April 24, 2016 22:06
@echenley
Copy link
Contributor Author

Yeah, the only alternative seems to be passing TextField state (or at least isFocused
hasValue and errorText) into TextFieldLabel and doing the logic there.

@nathanmarks
Copy link
Member

@echenley yeah, lesser of evils 😄

This is one of those annoying cases too where even JS non-inline styles won't make it cleaner either because the label doesn't actually get focussed when the input does, ah well!

@nathanmarks
Copy link
Member

nathanmarks commented Apr 24, 2016

@oliviertassinari

I've noticed a problem with the label color while checking out this PR in the docs -- not just on this PR but also on HEAD and 0.14.4 too.... should we fix this here?

MUI Docs

2016-04-24 at 6 19 pm

Spec

2016-04-24 at 6 18 pm

@echenley
Copy link
Contributor Author

echenley commented Apr 24, 2016

@nathanmarks Strange, I don't see this when I run the docs locally or here: http://www.material-ui.com/v0.15.0-beta.2/#/components/text-field

Edit: oh, I see it now. If it's focused and has text, it reverts to the default style. I'll add a fix.

@echenley echenley force-pushed the feature/floatingLabelFocusStyle branch from b800fe1 to f82b3ac Compare April 24, 2016 22:42
if (state.hasValue) {
styles.floatingLabel.color = fade(props.disabled ? disabledTextColor : floatingLabelColor, 0.5);
}

if (state.isFocused) {
styles.floatingLabel.color = focusColor;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nathanmarks Switching the order here fixes the focus color issue. Unless I'm missing why hasValue was overriding it.

@oliviertassinari oliviertassinari merged commit c824ad8 into mui:master Apr 25, 2016
@oliviertassinari
Copy link
Member

@echenley Nice PR, thanks👍.

@nathanmarks
Copy link
Member

@echenley Thanks for sorting that bug!!!

@Sabst
Copy link

Sabst commented Apr 30, 2016

Looks like after 0.15.0-beta.2 (included) this will allow for a dense text field.
Is this correct?
I read the different issues and the associated doc and still don't see how this should be used.
Let's say I need a text with a dense floating label (60dp high instead of the default 72dp).
Can you elaborate a bit more on how that works or provide a pointer to an example or doc?

@zannager zannager added the component: text field This is the name of the generic UI component, not the React module! label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More advanced component customization
5 participants