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] Make it meet guidelines #6566

Merged
merged 45 commits into from May 30, 2017

Conversation

kybarg
Copy link
Contributor

@kybarg kybarg commented Apr 10, 2017

@kybarg kybarg changed the title [TextField] Make it meet guidelines [TextField] Make it meet guidelines (next) Apr 10, 2017
@kybarg kybarg changed the title [TextField] Make it meet guidelines (next) [TextField] Make it meet guidelines Apr 10, 2017
@muibot muibot added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Apr 10, 2017
const dirty = props.children.some((child) => {
return child.type && child.type.name === 'Input' &&
child.props.value && child.props.value.length > 0;
});
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 looks complex. Any better way?

Copy link
Member

Choose a reason for hiding this comment

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

Good question! I can't think of a better alternative 🤔 .

@kybarg kybarg mentioned this pull request Apr 10, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 10, 2017

Notice that there is an ongoing effort for the multiline implementation #6553.

@oliviertassinari oliviertassinari added the component: text field This is the name of the generic UI component, not the React module! label Apr 10, 2017
@kybarg
Copy link
Contributor Author

kybarg commented Apr 10, 2017

@oliviertassinari that's great. Will take it into account.

constructor(props, context) {
super(props, context);

const dirty = props.children.some((child) => {
Copy link
Member

Choose a reason for hiding this comment

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

Nothing guarantee the props.children to be a flat array.

Copy link
Member

Choose a reason for hiding this comment

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

React provides a Children.map utility function.


const dirty = props.children.some((child) => {
return child.type && child.type.name === 'Input' &&
child.props.value && child.props.value.length > 0;
Copy link
Member

Choose a reason for hiding this comment

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

What about importing the isDirty function from the Input.js? I think that's safer that way.

const dirty = props.children.some((child) => {
return child.type && child.type.name === 'Input' &&
child.props.value && child.props.value.length > 0;
});
Copy link
Member

Choose a reason for hiding this comment

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

Good question! I can't think of a better alternative 🤔 .

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

Looks like it's going in the right direction 😄 .

@@ -78,6 +79,18 @@ export default class FormControl extends Component {
};
}

componentWillMount() {
let dirty = false;
Children.map(this.props.children, (child) => {
Copy link
Member

Choose a reason for hiding this comment

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

What about a forEach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this should work in this case)

root: {
color: theme.palette.input.helperText,
fontSize: 12,
lineHeight: 1.33333333,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that we need as many significant number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliviertassinari In Chrome 1.3333333 lineheight = 16px height, 1.333333 = 14 px 😄 I set it 1.4 also gives 16px but don't know how in can affect browsers when using retina display.

import customPropTypes from '../utils/customPropTypes';
import { FormLabel } from '../Form';

export const styleSheet = createStyleSheet('MuiTextFieldLabel', (theme) => {
Copy link
Member

Choose a reason for hiding this comment

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

Oops, a dead component 🙈 , good catch!

@@ -12,7 +12,7 @@ export const styleSheet = createStyleSheet('MuiFormHelperText', (theme) => {
root: {
color: theme.palette.input.helperText,
fontSize: 12,
lineHeight: 1.33333333,
lineHeight: 1.4,
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't 1.3' round to 1.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1.3 results to 15px line-height in webkit...

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha.

@oliviertassinari
Copy link
Member

oliviertassinari commented May 29, 2017

@kybarg The InputLabel extends the FormLabel, it's specifically designed for the input context.

I have one concern with the new height of the TextField.
While the height is incorrect on the current next branch, I think that we have the occasion to make it right: 62px with a label as correctly implemented by Polymer: https://www.webcomponents.org/element/PolymerElements/paper-input
capture d ecran 2017-05-29 a 21 54 39
And maybe 42px without the label or maybe not, I don't know:
capture d ecran 2017-05-29 a 21 59 56
What do you think? Increasing the height when a helper text is used is a good idea 👍 .

},
shrink: {
transform: 'translate(0, 0px) scale(0.75)',
transform: `translate(0, ${theme.spacing.unit * 2 + 2.5}px) scale(0.75)`,
Copy link
Member

Choose a reason for hiding this comment

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

I would avoid any 1/x px computation as unpredictable and subject to GPU floating error.

Copy link
Member

Choose a reason for hiding this comment

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

But why not keeping it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this hack, other inputs labels flicker when focusing one. Couldn't find better solution.
Only if we switch from transitions to animation.

@kybarg
Copy link
Contributor Author

kybarg commented May 29, 2017

@oliviertassinari I wouldn't stick with Polymer's implementation. Found many differences between it and official guidelines. material-components-web is better example but I think it is still too raw to follow.
I think you are right with 42px variant. I wanted default field to be 48px high. But it turns that 48px high field is different implementation (full-width field).

Placeholder styles look ugly. laceholder prefixing is to be impplemented
in next JSS versions.
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

material-web-components and polymer are two excellent reference implementation. Pick one and we will be happy 😄 .

easing: theme.transitions.easing.ease,
}),
},
'&:focus::-webkit-input-placeholder': {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use a single selector instead of repeating the opacity: property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliviertassinari JSS currently doesn't support prefixing ::placeholder selector. But there is discussion on this issue. Hope the will release it soon.

Copy link
Member

Choose a reason for hiding this comment

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

I was suggesting doing the following, but I'm not 100% sure it's working.

      '&:focus::-moz-placeholder, &:focus:-ms-input-placeholder, &:focus::-moz-placeholder, &:focus::-webkit-input-placeholder': {
        opacity: theme.palette.type === 'light' ? 0.42 : 0.5,
      },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliviertassinari unfortunately not 😢

…text-field-guidelines

# Conflicts:
#	src/styles/MuiThemeProvider.js
@kybarg
Copy link
Contributor Author

kybarg commented May 30, 2017

@oliviertassinari I've made this based on sticker sheet and specs
untitled-1
untitled-122

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

@mbrookes mbrookes left a comment

Choose a reason for hiding this comment

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

@kybarg So nearly there - just some tiny changes to standardize the prop labels, but before you follow my comments, when I got to the bottom there was this one:

image

@oliviertassinari Any preference?

@@ -115,6 +127,10 @@ FormControl.propTypes = {
*/
className: PropTypes.string,
/**
* If `true`, the label should be displayed in an disabled state.
*/
Copy link
Member

Choose a reason for hiding this comment

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

'a disabled state'

disabled: PropTypes.bool,
/**
* Whether the helper text should be displayed in an error state.
*/
Copy link
Member

Choose a reason for hiding this comment

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

'If true,'

*/
className: PropTypes.string,
/**
* Whether the helper text should be displayed in an disabled state.
Copy link
Member

Choose a reason for hiding this comment

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

'If true,' ... 'a disabled state.'

});

describe('prop: error', () => {
it('should show an error class', () => {
Copy link
Member

Choose a reason for hiding this comment

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

'should have an error class' / 'should set the error class'?

@@ -91,6 +100,10 @@ FormLabel.propTypes = {
*/
className: PropTypes.string,
/**
* Whether the label should be displayed in an disabled state.
Copy link
Member

Choose a reason for hiding this comment

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

'If true,' ... 'a disabled state.'

* Whether the label should be displayed in an disabled state.
*/
disabled: PropTypes.bool,
/**
* Whether the label should be displayed in an error state.
Copy link
Member

Choose a reason for hiding this comment

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

'If true,'

@@ -81,6 +86,10 @@ InputLabel.propTypes = {
*/
disableAnimation: PropTypes.bool,
/**
* If `true`, apply disabled class.
Copy link
Member

Choose a reason for hiding this comment

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

'If true, apply the disabled CSS class'.

Hmmm, now I wonder if all the others should follow that pattern. It's clearer to the user what the outcome of applying this prop is when it comes to custom styling.

@mbrookes mbrookes 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 May 30, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented May 30, 2017

@kybarg You rock, let's merge this 🚀 !

@oliviertassinari oliviertassinari merged commit 1c96695 into mui:next May 30, 2017
@oliviertassinari oliviertassinari removed 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 May 30, 2017
@kybarg kybarg deleted the next-text-field-guidelines branch May 30, 2017 20:08
@MichaelMure
Copy link
Contributor

Hello

After this merge, the height of a TextField is much bigger than previously, with a big margin on top. I didn't find a way to make it more compact. Is there one ?

Thank you for your work :)

@kybarg
Copy link
Contributor Author

kybarg commented Jun 1, 2017

@micaste Hi! Default input has height of 48px, with floating label 72px. This is what proposed by specs. But you can adjust it with styles.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 1, 2017

@kybarg I'm wondering if we shouldn't reduce the height of the TextField and expose an optional property to enable some margin, the margins suggested by the documentation.

@kybarg
Copy link
Contributor Author

kybarg commented Jun 1, 2017

@oliviertassinari I see spec as priority as it tries to cover most common cases. I believe non standard implementation is not very common 💭 Also I want to add "dense" variant. Maybe this can help in some cases as well 😄

@MichaelMure
Copy link
Contributor

@kybarg any style override to suggest ? I tried but I can only break the thing apparently.

@kybarg
Copy link
Contributor Author

kybarg commented Jun 2, 2017

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
9 participants