-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(icon): add :dir fallback #1223
Conversation
@supports selector(:dir(rtl)) { | ||
:host(.flip-rtl:dir(rtl)) .icon-inner { | ||
transform: scaleX(-1); | ||
} | ||
:host(.flip-rtl:dir(ltr)) .icon-inner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for WebKit otherwise the fallback will always cause the icon to be flipped if the document loads in RTL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be nice to have this comment in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I no longer have the right version of Safari to test this with, but it looks good to me. Thanks for figuring this all out!
@supports selector(:dir(rtl)) { | ||
:host(.flip-rtl:dir(rtl)) .icon-inner { | ||
transform: scaleX(-1); | ||
} | ||
:host(.flip-rtl:dir(ltr)) .icon-inner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be nice to have this comment in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me. +1 to adding a comment for why we have scaleX(1)
for the ltr
direction.
There are a couple things we missed with our first pass of #1210:
:host-context
nor:dir
have no fallback to at least set the dir correctly on page load.@supports selector(:dir(rtl))
evaluates totrue
in Safari <16.4 even though:dir
was supported starting in Safari 16.4. So even if we made a fallback such as above, it would not work on older versions of Safari.Solutions:
isRTL
check so at least the icon respects the dir on component load-webkit-named-image
and applied the RTL fallback. WebKit browsers that support:dir(rtl)
will override this fallback and get the reactive RTL behavior.Safari Bug Example: https://codepen.io/liamdebeasi/pen/eYPXPZY
Browsers that do not support
:dir(rtl)
should render a red square. Browsers that do support:dir(rtl)
should render a green square only when.square
hasdir="rtl"
(which it does in this template.Chrome: Red (Chrome doesn't support :dir yet so this result is fine)
Firefox: Green
Safari 16.4: Green
Safari <16.4: Nothing
Safari <16.4 reports that it supports
:dir(rtl)
so it never renders the red fallback. However, it never renders the green color either since it does not actually support:dir(rtl)
.