question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_invalid Input State Theming

See original GitHub issue

Description

Is there a reason this shouldn’t work?

export const chakraTheme = extendTheme({
  components: {
    FormLabel: {
      defaultProps: { _invalid: { textColor: 'red.100' } },
    },
  },
});

It works fine as a prop on the component but I want to have it be a default.

Problem Statement/Justification

This is important as to not having to individually set _invalid states on all components throughout a codebase. We should be able to theme it directly to apply to all components.

Proposed Solution or API

(see above snippet)

Alternatives

No response

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
primos63commented, Oct 22, 2021

My apologies. I misunderstood your issue as I was going by your theme where you list FormLabel. You’re looking to set the border color for an Input when the input is invalid, correct?

If so, then you need to look closely at the theme source.

// Theme source for Input
function getDefaults(props: Record<string, any>) {
  const { focusBorderColor: fc, errorBorderColor: ec } = props
  return {
    focusBorderColor: fc || mode("blue.500", "blue.300")(props),
    errorBorderColor: ec || mode("red.500", "red.300")(props),
  }
}

const variantOutline: PartsStyleFunction<typeof parts> = (props) => {
  const { theme } = props
  const { focusBorderColor: fc, errorBorderColor: ec } = getDefaults(props)
    
  return {
    field: {
      border: "1px solid",
      borderColor: "inherit",
      bg: "inherit",
      _hover: {
        borderColor: mode("gray.300", "whiteAlpha.400")(props),
      },
      _readOnly: {
        boxShadow: "none !important",
        userSelect: "all",
      },
      _disabled: {
        opacity: 0.4,
        cursor: "not-allowed",
      },
      _invalid: {
        borderColor: getColor(theme, ec),
        boxShadow: `0 0 0 1px ${getColor(theme, ec)}`,
      },
      _focus: {
        zIndex: 1,
        borderColor: getColor(theme, fc),
        boxShadow: `0 0 0 1px ${getColor(theme, fc)}`,
      },
    },

You have two options for setting the border color for an invalid Input. Option 1: Set the errorBorderColor in defaultProps

components: {
  Input: {
    defaultProps: {
      errorBorderColor: 'purple.500'
    }
  }
}

Option 2: Set the value of borderColor and boxShadow for _invalid within the variant you are using, default is outline

components: {
  Input: {
    variants: {
      outline: (props) => {
        const { theme } = props;
        return {
          field: {
            _invalid: {
              borderColor: "pink.500",
              boxShadow: `0 0 0 1px ${getColor(theme, "pink.500")}`
            }
          }
        }
      }
    },
  },
}
0reactions
Thebigbignoobycommented, May 26, 2022

What is the recommended way of changing the error color theme-wide?

ie: the default error color in the base theme is red.500 in light mode and red.300 in dark mode. I want to change it to red.400 for dark mode: do I have to set this for color and border for the Inputs and the FormError (duplicating a lot of code). or is there a more straightforward way of changing this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

invalid - CSS: Cascading Style Sheets - MDN Web Docs
The :invalid CSS pseudo-class represents any , , or other element whose contents fail to validate.
Read more >
Form Validation Styling on Input Focus
If an input is not in focus, its placeholder text isn't shown, and the entered text is invalid… then you can use these...
Read more >
How to target non-empty but invalid input elements with CSS
A clever CSS rule combining `:invalid` and `:placeholder-shown` to show validation state of non-empty input elements.
Read more >
Validation in HTML5. :invalid classe after submit
When a user modifies a field you remove the class. In your CSS you then apply styling to input:not(.hide-hints):invalid . This means the...
Read more >
Invalid Theme Warning - OutSystems 10 Documentation
Invalid Theme Warning ... Refer to the existing themes to check the necessary input parameters and entities that should be used in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found