[fix] better cross-browser support for textDecoration styles

Safari requires '-webkit' prefixes for CSS3 text-decoration styles, and
IE/Edge only support CSS2 text-decoration styles. This patch provides a
fallback for the CSS2 case and relies on the CSS3 properties for color
and style.

Close #1053

Co-authored-by: Nicolas Gallagher <nicolasgallagher@gmail.com>
This commit is contained in:
Anton Nyman
2018-07-27 12:54:07 +02:00
committed by Nicolas Gallagher
parent c7c1f29016
commit d29e31d9d6
2 changed files with 14 additions and 4 deletions
@@ -247,7 +247,9 @@ describe('StyleSheet/createReactDOMStyle', () => {
textDecorationStyle: 'dashed'
})
).toEqual({
textDecoration: 'underline dashed rgba(255,0,0,1.00)'
textDecoration: 'underline',
textDecorationColor: 'rgba(255,0,0,1.00)',
textDecorationStyle: 'dashed'
});
});
});
@@ -95,10 +95,18 @@ const resolveShadow = (resolvedStyle, style) => {
const resolveTextDecoration = (resolvedStyle, style) => {
const { textDecorationColor, textDecorationLine, textDecorationStyle } = style;
const color = normalizeColor(textDecorationColor) || '';
const lineStyle = textDecorationStyle || '';
const color = normalizeColor(textDecorationColor);
if (textDecorationLine) {
resolvedStyle.textDecoration = `${textDecorationLine} ${lineStyle} ${color}`.trim();
// use 'text-decoration' for browsers that support CSS2 text-decoration (e.g., IE, Edge)
resolvedStyle.textDecoration = textDecorationLine;
if (textDecorationColor) {
resolvedStyle.textDecorationColor = color;
}
if (textDecorationStyle) {
resolvedStyle.textDecorationStyle = textDecorationStyle;
}
}
};