Skip to content

Commit cfdd59e

Browse files
authored
Merge pull request Expensify#51117 from klajdipaja/issues/sign_in_dark_autofill_style
add extra css selector to global autofill style -add css class to the…
2 parents 038b21b + 81f38b0 commit cfdd59e

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

src/libs/DomUtils/index.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ const addCSS = (css: string, styleId: string) => {
3434
* Chrome on iOS does not support the autofill pseudo class because it is a non-standard webkit feature.
3535
* We should rely on the chrome-autofilled property being added to the input when users use auto-fill
3636
*/
37-
const getAutofilledInputStyle = (inputTextColor: string) => `
38-
input[chrome-autofilled],
39-
input[chrome-autofilled]:hover,
40-
input[chrome-autofilled]:focus,
41-
textarea[chrome-autofilled],
42-
textarea[chrome-autofilled]:hover,
43-
textarea[chrome-autofilled]:focus,
44-
select[chrome-autofilled],
45-
select[chrome-autofilled]:hover,
46-
select[chrome-autofilled]:focus,
47-
input:-webkit-autofill,
48-
input:-webkit-autofill:hover,
49-
input:-webkit-autofill:focus,
50-
textarea:-webkit-autofill,
51-
textarea:-webkit-autofill:hover,
52-
textarea:-webkit-autofill:focus,
53-
select:-webkit-autofill,
54-
select:-webkit-autofill:hover,
55-
select:-webkit-autofill:focus {
37+
const getAutofilledInputStyle = (inputTextColor: string, cssSelector = '') => `
38+
${cssSelector} input[chrome-autofilled],
39+
${cssSelector} input[chrome-autofilled]:hover,
40+
${cssSelector} input[chrome-autofilled]:focus,
41+
${cssSelector} textarea[chrome-autofilled],
42+
${cssSelector} textarea[chrome-autofilled]:hover,
43+
${cssSelector} textarea[chrome-autofilled]:focus,
44+
${cssSelector} select[chrome-autofilled],
45+
${cssSelector} select[chrome-autofilled]:hover,
46+
${cssSelector} select[chrome-autofilled]:focus,
47+
${cssSelector} input:-webkit-autofill,
48+
${cssSelector} input:-webkit-autofill:hover,
49+
${cssSelector} input:-webkit-autofill:focus,
50+
${cssSelector} textarea:-webkit-autofill,
51+
${cssSelector} textarea:-webkit-autofill:hover,
52+
${cssSelector} textarea:-webkit-autofill:focus,
53+
${cssSelector} select:-webkit-autofill,
54+
${cssSelector} select:-webkit-autofill:hover,
55+
${cssSelector} select:-webkit-autofill:focus {
5656
-webkit-background-clip: text;
5757
-webkit-text-fill-color: ${inputTextColor};
5858
caret-color: ${inputTextColor};

src/pages/signin/SignInPageLayout/index.tsx

+25
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import useTheme from '@hooks/useTheme';
1515
import useThemeStyles from '@hooks/useThemeStyles';
1616
import useWindowDimensions from '@hooks/useWindowDimensions';
1717
import * as Browser from '@libs/Browser';
18+
import DomUtils from '@libs/DomUtils';
19+
import getPlatform from '@libs/getPlatform';
20+
// eslint-disable-next-line no-restricted-imports
21+
import themes from '@styles/theme';
1822
import variables from '@styles/variables';
1923
import CONST from '@src/CONST';
2024
import BackgroundImage from './BackgroundImage';
@@ -81,6 +85,27 @@ function SignInPageLayout(
8185

8286
const backgroundImageHeight = Math.max(variables.signInContentMinHeight, containerHeight);
8387

88+
/*
89+
SignInPageLayout always has a dark theme regardless of the app theme. ThemeProvider sets auto-fill input styles globally so different ThemeProviders conflict and auto-fill input styles are incorrectly applied for this component.
90+
Add a class to `body` when this component stays mounted and remove it when the component dismounts.
91+
A new styleID is added with dark theme text with more specific css selector using this added cssClass.
92+
*/
93+
const cssClass = 'sign-in-page-layout';
94+
DomUtils.addCSS(DomUtils.getAutofilledInputStyle(themes[CONST.THEME.DARK].text, `.${cssClass}`), 'sign-in-autofill-input');
95+
96+
useEffect(() => {
97+
const isWeb = getPlatform() === CONST.PLATFORM.WEB;
98+
const isDesktop = getPlatform() === CONST.PLATFORM.DESKTOP;
99+
if (!isWeb && !isDesktop) {
100+
return;
101+
}
102+
// add css class to body only for web and desktop
103+
document.body.classList.add(cssClass);
104+
return () => {
105+
document.body.classList.remove(cssClass);
106+
};
107+
}, []);
108+
84109
return (
85110
<View style={containerStyles}>
86111
{!shouldUseNarrowLayout ? (

0 commit comments

Comments
 (0)