Skip to content

Commit

Permalink
[fix] textDecoration{Color,Line,Style} styles
Browse files Browse the repository at this point in the history
Attempting to fallback to CSS2 text-decoration is not reliable for inline
styles. This patch assumes CSS3 text-decoration support when server-rendering,
and uses CSS.supports to check for runtime support. When CSS3 support is
available the long-form properties are preserved.

Fix #1312
  • Loading branch information
necolas committed May 16, 2019
1 parent 37ca236 commit be5106f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ describe('StyleSheet/createReactDOMStyle', () => {
});
});

test('textDecorationLine', () => {
expect(
createReactDOMStyle({
textDecorationLine: 'underline'
})
).toEqual({
textDecoration: 'underline'
});
});

describe('transform', () => {
// passthrough if transform value is ever a string
test('string', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @noflow
*/

import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
import { MONOSPACE_FONT_STACK, SYSTEM_FONT_STACK, STYLE_SHORT_FORM_EXPANSIONS } from './constants';
import normalizeValueWithProperty from './normalizeValueWithProperty';

Expand All @@ -23,6 +24,13 @@ import normalizeValueWithProperty from './normalizeValueWithProperty';

const emptyObject = {};

const supportsCSS3TextDecoration =
!canUseDOM ||
(window.CSS != null &&
window.CSS.supports != null &&
(window.CSS.supports('text-decoration-line', 'none') ||
window.CSS.supports('-webkit-text-decoration-line', 'none')));

/**
* Transform
*/
Expand Down Expand Up @@ -144,7 +152,11 @@ const createReactDOMStyle = style => {
case 'textDecorationLine': {
// use 'text-decoration' for browsers that only support CSS2
// text-decoration (e.g., IE, Edge)
resolvedStyle.textDecoration = value;
if (!supportsCSS3TextDecoration) {
resolvedStyle.textDecoration = value;
} else {
resolvedStyle.textDecorationLine = value;
}
break;
}

Expand Down

0 comments on commit be5106f

Please sign in to comment.