Skip to content

Fix TextField color by state logic #631

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

Merged
merged 9 commits into from
Jan 28, 2020
Merged

Fix TextField color by state logic #631

merged 9 commits into from
Jan 28, 2020

Conversation

ethanshar
Copy link
Collaborator

We had some issues (only in public) with the TextField colors
I went over it and decided to do a little refactor there (also refactor the tests)

In general, the logic should make more sense now and follows closely are UX guidelines

@@ -330,7 +326,7 @@ export default class TextField extends BaseInput {
const {expandable, placeholder, placeholderTextColor, floatingPlaceholderColor, multiline}
= this.getThemeProps();
const typography = this.getTypography();
const placeholderColor = this.getStateColor(placeholderTextColor || DEFAULT_COLOR_BY_STATE.default);
const placeholderColor = this.getStateColor(placeholderTextColor || Colors.grey30);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why to hard-code the color and not use the DEFAULT_COLOR_BY_STATE.default (that should be set to 'grey30' instead of 'grey10')?

Copy link
Collaborator Author

@ethanshar ethanshar Jan 26, 2020

Choose a reason for hiding this comment

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

cause DEFAULT_COLOR_BY_STATE.default should be grey10 and not grey30

I'm assuming that DEFAULT_COLOR_BY_STATE is meant for the input text color
all the reset derive from it if needed or pass their own color if needed (like with the placeholder color)

Copy link
Collaborator

Choose a reason for hiding this comment

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

So why not hold a DEFAULT_PLACEHOLDER_COLOR_BY_STATE enum (like the DEFAULT_UNDERLINE_COLOR_BY_STATE) and get it from there instead of changing in 3 places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cause technically the behavior is different.
in line 329 I have
const placeholderColor = this.getStateColor(placeholderTextColor || Colors.grey30);
in line 350 I have
outputRange: [placeholderColor, this.getStateColor(floatingPlaceholderColor || {focus: Colors.blue30, default: Colors.grey30})]
which is different

and in line 500 I have this
const placeholderColor = this.getStateColor(placeholderTextColor || Colors.grey30);

The 2nd case is different than the other cause we want the color transition when the state changes from focused to not-focused.
In the other cases (1+3), we don't want a different color for the different states. so I pass the Colors.grey30. If anything I can defined a single const for DEFAULT_PLACEHOLDER_COLOR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've defined DEFAULT_PLACEHOLDER_COLOR const

@@ -351,7 +347,7 @@ export default class TextField extends BaseInput {
}),
color: floatingPlaceholderState.interpolate({
inputRange: [0, 1],
outputRange: [placeholderColor, this.getStateColor(floatingPlaceholderColor)]
outputRange: [placeholderColor, this.getStateColor(floatingPlaceholderColor || {focus: Colors.blue30, default: Colors.grey30})]
Copy link
Collaborator

@Inbal-Tish Inbal-Tish Jan 26, 2020

Choose a reason for hiding this comment

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

why to set all DEFAULT_COLOR_BY_STATE colors to 'grey10' if these are the defaults you want? Why to hard-code them here (and in line #368, and line #500)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was part of the bug with the colors.

The component assumed we have the same color states for placeholder and the input text color, but they're not the same according to the guidelines.
The color states for the input text is different than the color states of the placeholder

So basically, as I wrote in the previous comment DEFAULT_COLOR_BY_STATE represent the color states for the input text
and I pass a custom object for each part (placeholder, underline, etc..) according to our guidelines.

@ethanshar ethanshar requested a review from Inbal-Tish January 26, 2020 12:28
@@ -351,7 +347,7 @@ export default class TextField extends BaseInput {
}),
color: floatingPlaceholderState.interpolate({
inputRange: [0, 1],
outputRange: [placeholderColor, this.getStateColor(floatingPlaceholderColor)]
outputRange: [placeholderColor, this.getStateColor(floatingPlaceholderColor || {focus: Colors.blue30, default: DEFAULT_PLACEHOLDER_COLOR})]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand, why DEFAULT_PLACEHOLDER_COLOR is not an enum with states if you have 'focus' and 'default' cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -369,7 +365,7 @@ export default class TextField extends BaseInput {

renderTitle() {
const {floatingPlaceholder, title, titleColor, titleStyle} = this.getThemeProps();
const color = this.getStateColor(titleColor);
const color = this.getStateColor(titleColor || {focus: Colors.blue30, default: Colors.grey30});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use DEFAULT_PLACEHOLDER_COLOR here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@ethanshar ethanshar requested a review from Inbal-Tish January 28, 2020 08:37
@Inbal-Tish Inbal-Tish merged commit d321548 into master Jan 28, 2020
@ethanshar ethanshar deleted the fix/TextField_Colors branch May 17, 2020 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants