Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow easy styling autofilled of Inputs #1811

Merged
merged 4 commits into from Jun 12, 2021
Merged

Allow easy styling autofilled of Inputs #1811

merged 4 commits into from Jun 12, 2021

Conversation

hasparus
Copy link
Member

@hasparus hasparus commented Jun 10, 2021

Image from Gyazo

Release Notes

Background color of autofilled inputs will now default to theme.colors.background. It can be changed by setting autofillBackgroundColor prop.

📦 Published PR as canary version: 0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0

✨ Test out this PR locally via:

npm install @theme-ui/color-modes@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/color@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/components@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/core@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/css@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/custom-properties@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/editor@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install gatsby-plugin-theme-ui@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install gatsby-theme-style-guide@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install gatsby-theme-ui-layout@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/match-media@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/mdx@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/parse-props@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-base@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-bootstrap@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-bulma@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-dark@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-deep@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-funk@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-future@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-polaris@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-roboto@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-sketchy@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-swiss@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-system@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-tailwind@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/preset-tosh@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/presets@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/prism@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/sidenav@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/style-guide@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/tachyons@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/tailwind@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/theme-provider@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install theme-ui@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
npm install @theme-ui/typography@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
# or 
yarn add @theme-ui/color-modes@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/color@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/components@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/core@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/css@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/custom-properties@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/editor@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add gatsby-plugin-theme-ui@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add gatsby-theme-style-guide@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add gatsby-theme-ui-layout@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/match-media@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/mdx@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/parse-props@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-base@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-bootstrap@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-bulma@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-dark@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-deep@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-funk@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-future@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-polaris@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-roboto@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-sketchy@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-swiss@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-system@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-tailwind@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/preset-tosh@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/presets@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/prism@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/sidenav@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/style-guide@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/tachyons@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/tailwind@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/theme-provider@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add theme-ui@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0
yarn add @theme-ui/typography@0.10.0-canary.1811.dd54586b88593673789513c59bcbe0235916cbf1.0

@hasparus hasparus added enhancement New feature or request @theme-ui/components labels Jun 10, 2021
@hasparus hasparus requested a review from lachlanjc June 10, 2021 12:16
@vercel
Copy link

vercel bot commented Jun 10, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/systemui/theme-ui/5jouzaxFcW2fbVmDnNDzFJbNQvJ5
✅ Preview: https://theme-ui-git-autofill-input-bg-systemui.vercel.app

@hasparus hasparus added the patch Increment the patch version when merged label Jun 10, 2021
@hasparus
Copy link
Member Author

@flo-sch you might be interested in this PR (BTW, is there a way to contact you outside of GitHub?)

@flo-sch
Copy link
Collaborator

flo-sch commented Jun 11, 2021

Nice feature :)

The interwebs provide many ways, are you thinking of a specific one?

@hasparus
Copy link
Member Author

The interwebs provide many ways, are you thinking of a specific one?

Okay, I've sent you an e-mail through the contact form :)

@hasparus hasparus merged commit aeb44b8 into develop Jun 12, 2021
@hasparus hasparus deleted the autofill-input-bg branch June 12, 2021 06:41
@hasparus
Copy link
Member Author

🚀 PR was released in v0.10.0 🚀

@hasparus hasparus added the released This issue/pull request has been released. label Jun 19, 2021
@flo-sch
Copy link
Collaborator

flo-sch commented Oct 12, 2021

Hello @hasparus, small related question before I open another issue / PR, seems like the autofillBackgroundColor is missing in the Input types maybe?

Property 'autofillBackgroundColor' does not exist on type 'IntrinsicAttributes & Pick<InputProps, "name" | "form" | "p" | "slot" | "style" | "title" | "pattern" | "className" | "key" | "autoComplete" | ... 311 more ... | "step"> & RefAttributes<...> & SxProp'.ts

Also a small question/suggestion: what about defining a specific key under theme.colors so that we could directly set it as part of the theme (or a variant), instead of having to set it as a prop (on each <Input />)?
I was thinking about changing the prop default value:

Not sure if there is an extra smart way to achieve that, but maybe something like (potentially breaking change?):

sx={{
  '--theme-ui-input-autofill-bg': (theme) => get(
    theme.colors,
    // first try to apply theme.colors.autofillBackgroundColor if it is defined
    'autofillBackgroundColor',
    // fallback to the prop value otherwise
    get(theme.colors, autofillBackgroundColor, null)
  ),
  ...sx,
}}

@hasparus
Copy link
Member Author

Hello @hasparus, small related question before I open another issue / PR, seems like the autofillBackgroundColor is missing in the Input types maybe?

Oh, that's definitely a bug. Do you wanna add it?

Not sure if there is an extra smart way to achieve that, but maybe something like (potentially breaking change?):

To be fair, I'm not sure about it. If we're editing the theme already we might pass this color to a variant?

@flo-sch
Copy link
Collaborator

flo-sch commented Oct 14, 2021

Oh, that's definitely a bug. Do you wanna add it?

Yep, I can take that :)

To be fair, I'm not sure about it. If we're editing the theme already we might pass this color to a variant?

I have tried to add it as a variant but somehow it always gets overridden by the prop (even when not set --> fallback to background), I think because the <Input /> __css (with default style, including that autofill rule) is placed after sx={{ ... }} and is evaluated afterwards (as "more specific") by the browser? 🤔

// CustomTheme.ts
{
  forms: {
    someVariant: {
      // ...
      '--theme-ui-input-autofill-bg': (theme) => get(theme.colors || {}, 'highlight', null) as string,
    }
  }
}

--> The default Input style overrides it anyway

theme-ui-input-autofill-bg

I could make it work by re-adding the same rules as part of the variant, bit cumbersome but it works:

// CustomTheme.ts
{
  forms: {
    someVariant: {
      // ...
      ':autofill, :autofill:hover, :autofill:focus': {
        boxShadow: (theme) =>
          `inset 0 0 0 1000px ${get(theme.colors || {}, 'highlight', 'lightgrey') as string}`
      },
      ':-webkit-autofill, :-webkit-autofill:hover, :-webkit-autofill:focus': {
        boxShadow: (theme) =>
          `inset 0 0 0 1000px ${get(theme.colors || {}, 'muted', 'lightgrey') as string}`
      }
    }
  }
}

(Is there any better way to type get()? 🤔 )

@xyzzyxyzzy0077
Copy link

Thanks for the great work! Is there any update on fixing autofillBackgroundColor not in the input types issue?

@lachlanjc
Copy link
Member

Not that I'm aware of, @xyzzyxyzzy0077! @flo-sch did you end up looking into that?

@flo-sch
Copy link
Collaborator

flo-sch commented Feb 4, 2022

Ah, I forgot about that sorry, but I should be able to very soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request patch Increment the patch version when merged released This issue/pull request has been released. @theme-ui/components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants