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.

Alert colorScheme's defaultProps is not taken into consideration

See original GitHub issue

Description

Hello,

I wanted to create an alert that has a grey colorScheme by default. But when I try to override Alert’s theme I came across a different behavior than I expected.

Problem Statement/Justification

My need is that:

<Alert>
...

Would render a grey alert. So I went ahead and override Alert’s theme with:

const defaultProps = {
  variant: "solid",
  colorScheme: "gray", // gray is a valid colorScheme
};

In this case, the solid defaultProps is taken into consideration, but the colorScheme is not. Unfortunately, the underlying code seems to set the colorScheme to “blue” (via STATUS.info) when we don’t explicitly set a colorScheme props.

Proposed Solution or API

I expect

const defaultProps = {
  variant: "solid",
  colorScheme: "gray", // gray is a valid colorScheme
};

To allow to use Alert without specifying the colorScheme props each time in inline props

Alternatives

No response

Additional Information

Thanks for the great work with Chakra-ui 😄

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
praveenpugliacommented, Aug 8, 2022

Encountering the same issue.

withDefaultColorScheme({
    colorScheme: 'red',
    components: ['Alert'],
  }),

Something like this definitely works for checkbox or buttons etc but for for alert, i still get the default blue.

0reactions
stale[bot]commented, Apr 27, 2022

Hi! This issue has been automatically marked as stale because lack of recent activity. It will be closed if no further activity occurs within 5 days. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eslint: Problem with default props in functional component ...
Eslint react plugin complain with this error ESLint: propType "gretting" is not required, but has no corresponding defaultProps declaration.( ...
Read more >
r/reactjs - React defaultProps is dying, who's the contender?
The main issue is that if we're talking about non primitive default values, they will cause re render of child components if passed....
Read more >
Flex UI Configuration | Twilio
Information on how to modify the Twilio Flex UI, using either the Flex Configuration Object or the defaultProps API.
Read more >
Breaking changes in v5, part one: styles and themes - MUI
This is a reference guide to all of the breaking changes introduced in Material v5, and how to handle them when migrating from...
Read more >
Theming React components with Tailwind CSS
Now create a Button.js file inside that. We'll use the colors we defined in our Tailwind config to define the background and text...
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