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

floating label rtl fix #11324

Merged
merged 5 commits into from
Apr 24, 2017
Merged

Conversation

sijav
Copy link
Contributor

@sijav sijav commented Apr 22, 2017

Add RTL support to Floating labels

Short description of what this resolves:

RTL support for floating labels

Changes proposed in this pull request:

  • added a scss code which set transform-origin to right for RTL direction on html.

Ionic Version: 2.x / 3.x

add rtl fix to floating label
@AmitMY
Copy link
Contributor

AmitMY commented Apr 22, 2017

Thank you for creating a pull request for RTL, its great to see more people helping on that.
As this is your first contribution, please read the "creating a pull request" guide, and commit message style under it.

This is a great change, but it is missing all-platforms support.
There is also .label-ios[floating] and .label-wp[floating] that need to be addressed.

@@ -48,6 +48,12 @@ $label-md-margin: $item-md-padding-top ($item-md-padding-rig
transition: transform 150ms ease-in-out;
}

html[dir=rtl] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Preferably, use [dir="rtl"] instead, to give the option to use rtl on any html component

@@ -48,6 +48,12 @@ $label-md-margin: $item-md-padding-top ($item-md-padding-rig
transition: transform 150ms ease-in-out;
}

html[dir=rtl] {
.label-md[floating] {
Copy link
Contributor

Choose a reason for hiding this comment

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

When it is a single block, preferably, use [dir="rtl"] .label-md[floating] instead of nesting. (see segment)

problems with transform-origin with both windows and ios platform for
rtl and also wrong translate3d for rtl for windows platform
@@ -56,6 +61,11 @@ $label-wp-text-color-focused: color($colors-wp, primary) !default;
transform: translate3d(0, 0, 0) scale(.8);
}

html[dir="rtl"] .input-has-focus .label-wp[floating],
Copy link
Contributor

@AmitMY AmitMY Apr 22, 2017

Choose a reason for hiding this comment

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

This rtl behavior is exactly the same as ltr behavior, so no need to write it again (entire block)

Copy link
Contributor Author

@sijav sijav Apr 22, 2017

Choose a reason for hiding this comment

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

actually it's needed as the [dir="rtl"] .label-wp[floating] transform: translate3d will replace the .input-has-focus .label-wp[floating] transform: translate3d on rtl

@@ -40,6 +40,11 @@ $label-wp-text-color-focused: color($colors-wp, primary) !default;
transform-origin: left top;
}

html[dir="rtl"] .label-wp[floating] {
transform: translate3d(-8px, 34px, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This rtl behavior is exactly the same as ltr behavior, so no need to write it again (this specific 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.

The ltr translate 8px to the right, this one translate it to the left (-8px instead of 8px), am I missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I was missing it. Thanks

@@ -48,6 +48,10 @@ $label-md-margin: $item-md-padding-top ($item-md-padding-rig
transition: transform 150ms ease-in-out;
}

html[dir="rtl"] .label-md[floating] {
transform-origin: right top;
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is 4 spaces instead of 2

remove reference of "html", just plain '[dir="rtl"]
indent 2 space instead of 4
@@ -61,8 +61,8 @@ html[dir="rtl"] .label-wp[floating] {
transform: translate3d(0, 0, 0) scale(.8);
}

html[dir="rtl"] .input-has-focus .label-wp[floating],
html[dir="rtl"] .input-has-value .label-wp[floating] {
[dir="rtl"] .input-has-focus .label-wp[floating],
Copy link
Contributor

Choose a reason for hiding this comment

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

This one still looks the same to me, both for ltr and rtl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I've added a transform: translate3d with more specific reference then a class (an attribute) it will replace the original LTR (.input-has-focus or .input-has-value), with default one so the label won't float on RTL direction, therefore I've added the same thing with attribute specific (dir="rtl") ... it's hackish, I know, but couldn't find a better suitable easy way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what you mean...
I am referring to:

.input-has-focus .label-wp[floating],
.input-has-value .label-wp[floating] {
  transform: translate3d(0, 0, 0) scale(.8);
}

[dir="rtl"] .input-has-focus .label-wp[floating],
[dir="rtl"] .input-has-value .label-wp[floating] {
  transform: translate3d(0, 0, 0) scale(.8);
}

Which as I see it, is equivalent to:

.input-has-focus .label-wp[floating],
.input-has-value .label-wp[floating] {
  transform: translate3d(0, 0, 0) scale(.8);
}

Because you override the ltr with the same behavior

Copy link
Contributor Author

@sijav sijav Apr 22, 2017

Choose a reason for hiding this comment

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

Easy,
unfortunately the browser will choose this rule

[dir="rtl"] .label-wp[floating] {
  transform: translate3d(-8px, 34px, 0);
}

over this one

.input-has-focus .label-wp[floating],
.input-has-value .label-wp[floating] {
  transform: translate3d(0, 0, 0) scale(.8);
}

even if the label has a parent element with input-has-focus class because of the attribute specification from previous rule which has a higher priority than a class. so I've added exactly the same thing over again with attribute specification, so the browser choose the right one on focus or when the input has value in rtl mode...
This can be easily seen in a test, try to remove those three line code and test a wp platform you'll see the floating label won't float and won't go up on focus.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. ok.
I might nor know enough about CSS priorities, but from a small test, it seems like it goes like I said it would: https://codepen.io/anon/pen/BRzxza

As far as I understand, that is because of the order of selectors:
.input-has-focus .label-wp[floating] is after [dir="rtl"] .label-wp[floating] and thus takes president.

Let me know if you still think otherwise (as again, I am not completely sure of it)

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, you're right, sorry, my bad, my way of testing this was wrong!

remove unnecessary duplicate rule
@AmitMY
Copy link
Contributor

AmitMY commented Apr 22, 2017

@manucorporat @brandyscarney This looks done. Can you merge? (and add rtl label)

@sijav
Copy link
Contributor Author

sijav commented Apr 23, 2017

I'm creating another pr which contains this too.
So I'm closing this.

@sijav sijav closed this Apr 23, 2017
@AmitMY
Copy link
Contributor

AmitMY commented Apr 23, 2017

In theory, PRs should be "Small, independent, complete contributions" such that it is preferable to have 2 different PRs rather than 1 PR with 2 features.
If your new PR fixes more labels, than it should be 1 PR, otherwise 2.

If you are interested in learning more -

@sijav
Copy link
Contributor Author

sijav commented Apr 23, 2017

@AmitMY So I should open this and make some new other PR for my other changes? sorry I'm new to this.

@AmitMY
Copy link
Contributor

AmitMY commented Apr 23, 2017

@sijav No problem :)
Yes, imo, and the theory suggest, that is better if you open it and create a new PR for any other feature.

I really recommend that video, it explains a lot about open source PRs and the review process

@sijav
Copy link
Contributor Author

sijav commented Apr 23, 2017

Yes, Thanks a lot,

@sijav sijav reopened this Apr 23, 2017
@brandyscarney brandyscarney merged commit 0ec71cd into ionic-team:master Apr 24, 2017
@brandyscarney
Copy link
Member

This looks great! Thank you @sijav for the PR, and @AmitMY for doing a great job reviewing and providing feedback. 🙂 🎉

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.

4 participants