Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1811 from system-ui/autofill-input-bg
- Loading branch information
Showing
9 changed files
with
178 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
import React from 'react' | ||
import Box from './Box' | ||
|
||
export const Input = React.forwardRef(function Input(props, ref) { | ||
import { get } from '@theme-ui/css' | ||
|
||
/** @type {import('theme-ui').ThemeUIStyleObject} */ | ||
const autofillStyles = { | ||
boxShadow: 'inset 0 0 0 1000px var(--theme-ui-input-autofill-bg)', | ||
fontSize: 'inherit', | ||
':first-line': { | ||
fontSize: '1rem', | ||
}, | ||
} | ||
|
||
/** @type {import('theme-ui').ThemeUIStyleObject} */ | ||
const defaultInputStyles = { | ||
display: 'block', | ||
width: '100%', | ||
p: 2, | ||
appearance: 'none', | ||
fontSize: 'inherit', | ||
lineHeight: 'inherit', | ||
border: '1px solid', | ||
borderRadius: 4, | ||
color: 'inherit', | ||
bg: 'transparent', | ||
|
||
':autofill, :autofill:hover, :autofill:focus': autofillStyles, | ||
':-webkit-autofill, :-webkit-autofill:hover, :-webkit-autofill:focus': | ||
autofillStyles, | ||
} | ||
|
||
export const Input = React.forwardRef(function Input( | ||
{ sx, autofillBackgroundColor = 'background', ...rest }, | ||
ref | ||
) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
as="input" | ||
variant="input" | ||
{...props} | ||
__themeKey="forms" | ||
__css={{ | ||
display: 'block', | ||
width: '100%', | ||
p: 2, | ||
appearance: 'none', | ||
fontSize: 'inherit', | ||
lineHeight: 'inherit', | ||
border: '1px solid', | ||
borderRadius: 4, | ||
color: 'inherit', | ||
bg: 'transparent', | ||
sx={{ | ||
'--theme-ui-input-autofill-bg': (theme) => | ||
get(theme.colors, autofillBackgroundColor, null), | ||
...sx, | ||
}} | ||
{...rest} | ||
__themeKey="forms" | ||
__css={defaultInputStyles} | ||
/> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aeb44b8
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.
Successfully deployed to the following URLs: