Skip to content

Commit d5bbc66

Browse files
committed
[theme] Add var for webkit autofill color
1 parent 3ae6695 commit d5bbc66

File tree

6 files changed

+110
-108
lines changed

6 files changed

+110
-108
lines changed

packages/mui-material/src/FilledInput/FilledInput.js

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -203,80 +203,73 @@ const FilledInputInput = styled(InputBaseInput, {
203203
slot: 'Input',
204204
overridesResolver: inputBaseInputOverridesResolver,
205205
})(
206-
memoTheme(({ theme }) => ({
207-
paddingTop: 25,
208-
paddingRight: 12,
209-
paddingBottom: 8,
210-
paddingLeft: 12,
211-
...(!theme.vars && {
212-
'&:-webkit-autofill': {
213-
WebkitBoxShadow: theme.palette.mode === 'light' ? null : '0 0 0 100px #266798 inset',
214-
WebkitTextFillColor: theme.palette.mode === 'light' ? null : '#fff',
215-
caretColor: theme.palette.mode === 'light' ? null : '#fff',
216-
borderTopLeftRadius: 'inherit',
217-
borderTopRightRadius: 'inherit',
218-
},
219-
}),
220-
...(theme.vars && {
206+
memoTheme(({ theme }) => {
207+
const light = theme.palette.mode === 'light';
208+
const webkitShadowBox = light ? 'unset' : '0 0 0 100px #266798 inset';
209+
const webkitTextFillColor = light ? 'unset' : '#fff';
210+
const caretColor = light ? 'unset' : '#fff';
211+
return {
212+
paddingTop: 25,
213+
paddingRight: 12,
214+
paddingBottom: 8,
215+
paddingLeft: 12,
221216
'&:-webkit-autofill': {
217+
WebkitBoxShadow: theme.vars
218+
? theme.vars.palette.FilledInput.autofillWebkitShadowBox
219+
: webkitShadowBox,
220+
WebkitTextFillColor: webkitTextFillColor,
221+
caretColor,
222222
borderTopLeftRadius: 'inherit',
223223
borderTopRightRadius: 'inherit',
224224
},
225-
[theme.getColorSchemeSelector('dark')]: {
226-
'&:-webkit-autofill': {
227-
WebkitBoxShadow: '0 0 0 100px #266798 inset',
228-
WebkitTextFillColor: '#fff',
229-
caretColor: '#fff',
230-
},
231-
},
232-
}),
233-
variants: [
234-
{
235-
props: {
236-
size: 'small',
237-
},
238-
style: {
239-
paddingTop: 21,
240-
paddingBottom: 4,
225+
variants: [
226+
{
227+
props: {
228+
size: 'small',
229+
},
230+
style: {
231+
paddingTop: 21,
232+
paddingBottom: 4,
233+
},
241234
},
242-
},
243-
{
244-
props: ({ ownerState }) => ownerState.hiddenLabel,
245-
style: {
246-
paddingTop: 16,
247-
paddingBottom: 17,
235+
{
236+
props: ({ ownerState }) => ownerState.hiddenLabel,
237+
style: {
238+
paddingTop: 16,
239+
paddingBottom: 17,
240+
},
248241
},
249-
},
250-
{
251-
props: ({ ownerState }) => ownerState.startAdornment,
252-
style: {
253-
paddingLeft: 0,
242+
{
243+
props: ({ ownerState }) => ownerState.startAdornment,
244+
style: {
245+
paddingLeft: 0,
246+
},
254247
},
255-
},
256-
{
257-
props: ({ ownerState }) => ownerState.endAdornment,
258-
style: {
259-
paddingRight: 0,
248+
{
249+
props: ({ ownerState }) => ownerState.endAdornment,
250+
style: {
251+
paddingRight: 0,
252+
},
260253
},
261-
},
262-
{
263-
props: ({ ownerState }) => ownerState.hiddenLabel && ownerState.size === 'small',
264-
style: {
265-
paddingTop: 8,
266-
paddingBottom: 9,
254+
{
255+
props: ({ ownerState }) => ownerState.hiddenLabel && ownerState.size === 'small',
256+
style: {
257+
paddingTop: 8,
258+
paddingBottom: 9,
259+
},
267260
},
268-
},
269-
{
270-
props: ({ ownerState }) => ownerState.multiline,
271-
style: {
272-
paddingTop: 0,
273-
paddingBottom: 0,
274-
paddingLeft: 0,
275-
paddingRight: 0,
261+
{
262+
props: ({ ownerState }) => ownerState.multiline,
263+
style: {
264+
paddingTop: 0,
265+
paddingBottom: 0,
266+
paddingLeft: 0,
267+
paddingRight: 0,
268+
},
276269
},
277-
},
278-
],
279-
})),
270+
],
271+
};
272+
}),
280273
);
281274

282275
const FilledInput = React.forwardRef(function FilledInput(inProps, ref) {

packages/mui-material/src/OutlinedInput/OutlinedInput.js

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -134,57 +134,51 @@ const OutlinedInputInput = styled(InputBaseInput, {
134134
slot: 'Input',
135135
overridesResolver: inputBaseInputOverridesResolver,
136136
})(
137-
memoTheme(({ theme }) => ({
138-
padding: '16.5px 14px',
139-
...(!theme.vars && {
140-
'&:-webkit-autofill': {
141-
WebkitBoxShadow: theme.palette.mode === 'light' ? null : '0 0 0 100px #266798 inset',
142-
WebkitTextFillColor: theme.palette.mode === 'light' ? null : '#fff',
143-
caretColor: theme.palette.mode === 'light' ? null : '#fff',
144-
borderRadius: 'inherit',
145-
},
146-
}),
147-
...(theme.vars && {
137+
memoTheme(({ theme }) => {
138+
const light = theme.palette.mode === 'light';
139+
const webkitShadowBox = light ? 'unset' : '0 0 0 100px #266798 inset';
140+
const webkitTextFillColor = light ? 'unset' : '#fff';
141+
const caretColor = light ? 'unset' : '#fff';
142+
return {
143+
padding: '16.5px 14px',
148144
'&:-webkit-autofill': {
145+
WebkitBoxShadow: theme.vars
146+
? theme.vars.palette.OutlinedInput.autofillWebkitShadowBox
147+
: webkitShadowBox,
148+
WebkitTextFillColor: webkitTextFillColor,
149+
caretColor,
149150
borderRadius: 'inherit',
150151
},
151-
[theme.getColorSchemeSelector('dark')]: {
152-
'&:-webkit-autofill': {
153-
WebkitBoxShadow: '0 0 0 100px #266798 inset',
154-
WebkitTextFillColor: '#fff',
155-
caretColor: '#fff',
156-
},
157-
},
158-
}),
159-
variants: [
160-
{
161-
props: {
162-
size: 'small',
163-
},
164-
style: {
165-
padding: '8.5px 14px',
152+
variants: [
153+
{
154+
props: {
155+
size: 'small',
156+
},
157+
style: {
158+
padding: '8.5px 14px',
159+
},
166160
},
167-
},
168-
{
169-
props: ({ ownerState }) => ownerState.multiline,
170-
style: {
171-
padding: 0,
161+
{
162+
props: ({ ownerState }) => ownerState.multiline,
163+
style: {
164+
padding: 0,
165+
},
172166
},
173-
},
174-
{
175-
props: ({ ownerState }) => ownerState.startAdornment,
176-
style: {
177-
paddingLeft: 0,
167+
{
168+
props: ({ ownerState }) => ownerState.startAdornment,
169+
style: {
170+
paddingLeft: 0,
171+
},
178172
},
179-
},
180-
{
181-
props: ({ ownerState }) => ownerState.endAdornment,
182-
style: {
183-
paddingRight: 0,
173+
{
174+
props: ({ ownerState }) => ownerState.endAdornment,
175+
style: {
176+
paddingRight: 0,
177+
},
184178
},
185-
},
186-
],
187-
})),
179+
],
180+
};
181+
}),
188182
);
189183

190184
const OutlinedInput = React.forwardRef(function OutlinedInput(inProps, ref) {

packages/mui-material/src/styles/createThemeFoundation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export interface PaletteFilledInput {
153153
bg: string;
154154
hoverBg: string;
155155
disabledBg: string;
156+
autofillWebkitShadowBox: string;
156157
}
157158

158159
export interface PaletteLinearProgress {
@@ -164,6 +165,10 @@ export interface PaletteLinearProgress {
164165
warningBg: string;
165166
}
166167

168+
export interface PaletteOutlinedInput {
169+
autofillWebkitShadowBox: string;
170+
}
171+
167172
export interface PaletteSkeleton {
168173
bg: string;
169174
}
@@ -237,6 +242,7 @@ export interface ColorSystemOptions {
237242
Chip?: Partial<PaletteChip>;
238243
FilledInput?: Partial<PaletteFilledInput>;
239244
LinearProgress?: Partial<PaletteLinearProgress>;
245+
OutlinedInput?: Partial<PaletteOutlinedInput>;
240246
Skeleton?: Partial<PaletteSkeleton>;
241247
Slider?: Partial<PaletteSlider>;
242248
SnackbarContent?: Partial<PaletteSnackbarContent>;
@@ -270,6 +276,7 @@ export interface CssVarsPalette {
270276
Chip: PaletteChip;
271277
FilledInput: PaletteFilledInput;
272278
LinearProgress: PaletteLinearProgress;
279+
OutlinedInput: PaletteOutlinedInput;
273280
Skeleton: PaletteSkeleton;
274281
Slider: PaletteSlider;
275282
SnackbarContent: PaletteSnackbarContent;

packages/mui-material/src/styles/createThemeWithVars.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
PaletteChip,
2020
PaletteFilledInput,
2121
PaletteLinearProgress,
22+
PaletteOutlinedInput,
2223
PaletteSkeleton,
2324
PaletteSlider,
2425
PaletteSnackbarContent,
@@ -59,6 +60,7 @@ export type {
5960
PaletteChip,
6061
PaletteFilledInput,
6162
PaletteLinearProgress,
63+
PaletteOutlinedInput,
6264
PaletteSkeleton,
6365
PaletteSlider,
6466
PaletteSnackbarContent,

packages/mui-material/src/styles/createThemeWithVars.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export default function createThemeWithVars(options = {}, ...args) {
247247
'Chip',
248248
'FilledInput',
249249
'LinearProgress',
250+
'OutlinedInput',
250251
'Skeleton',
251252
'Slider',
252253
'SnackbarContent',
@@ -312,6 +313,7 @@ export default function createThemeWithVars(options = {}, ...args) {
312313
setColor(palette.FilledInput, 'bg', 'rgba(0, 0, 0, 0.06)');
313314
setColor(palette.FilledInput, 'hoverBg', 'rgba(0, 0, 0, 0.09)');
314315
setColor(palette.FilledInput, 'disabledBg', 'rgba(0, 0, 0, 0.12)');
316+
setColor(palette.FilledInput, 'autofillWebkitShadowBox', 'unset');
315317
setColor(
316318
palette.LinearProgress,
317319
'primaryBg',
@@ -334,6 +336,7 @@ export default function createThemeWithVars(options = {}, ...args) {
334336
'warningBg',
335337
colorMix(safeLighten, palette.warning.main, 0.62),
336338
);
339+
setColor(palette.OutlinedInput, 'autofillWebkitShadowBox', 'unset');
337340
setColor(
338341
palette.Skeleton,
339342
'bg',
@@ -461,6 +464,7 @@ export default function createThemeWithVars(options = {}, ...args) {
461464
setColor(palette.FilledInput, 'bg', 'rgba(255, 255, 255, 0.09)');
462465
setColor(palette.FilledInput, 'hoverBg', 'rgba(255, 255, 255, 0.13)');
463466
setColor(palette.FilledInput, 'disabledBg', 'rgba(255, 255, 255, 0.12)');
467+
setColor(palette.FilledInput, 'autofillWebkitShadowBox', '0 0 0 100px #266798 inset');
464468
setColor(
465469
palette.LinearProgress,
466470
'primaryBg',
@@ -483,6 +487,7 @@ export default function createThemeWithVars(options = {}, ...args) {
483487
'warningBg',
484488
colorMix(safeDarken, palette.warning.main, 0.5),
485489
);
490+
setColor(palette.OutlinedInput, 'autofillWebkitShadowBox', '0 0 0 100px #266798 inset');
486491
setColor(
487492
palette.Skeleton,
488493
'bg',

packages/mui-material/src/styles/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export type {
142142
PaletteCommonChannel,
143143
PaletteFilledInput,
144144
PaletteLinearProgress,
145+
PaletteOutlinedInput,
145146
PaletteSkeleton,
146147
PaletteSlider,
147148
PaletteSnackbarContent,

0 commit comments

Comments
 (0)