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.

Pass props defined in the theme .defaultProps to the components

See original GitHub issue

(Opening this ticket so the conversation doesn’t get lost on discord)

Right now only stylistic props in the defaultProps section of the component theme are used. Any other properties are ignored. (See codesanbox)

There is a bunch of non-stylistic properties that would benefit from being passed to the underlying component. Some examples:

  • Being able to set a default openDelay on all tooltips.
  • Being able to set all tooltips with hasArrow.
  • Being able to set a default as on the different variants/sizes of Heading.
  • Overriding the default aria-label on components like the CloseButton (e.g. translating it to other languages).

Right now the only alternative would be to create a custom wrapper component that sets those defaults props.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:38
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

12reactions
cloud-walkercommented, Dec 11, 2020

Hi all, I know it may be a bit hacky, but I thought it was good to share: you can actually override the defaultProps as follows

// my-theme.js

import {extendTheme, Tooltip} from '@chakra-ui/react'

// ...

Tooltip.defaultProps = {...Tooltip.defaultProps, hasArrow: true}

Have a good weekend!

9reactions
with-heartcommented, Jul 27, 2020

I think this is a great idea. These are valid, common sense use cases. Wrapper components are also the worst.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A complete guide to React default props - LogRocket Blog
Cover three ways to implement default props in React and provide default values for props that are not required by the component.
Read more >
How to pass material-ui's theme object to defaultProps?
I'm just rubber ducking something here. Since I'm still passing backgroundColor as a prop to my Example component I'm just wondering how to ......
Read more >
React: Everything about Default Props | by Chidume Nnamdi
In this post, we'll learn all about default props in React. ... defaultProps can be defined as a property on the component class...
Read more >
Default props - Mantine
Default props. You can define default props for every Mantine component by setting theme.components on MantineProvider: Within provider.
Read more >
Default Values - Styled System
With the default props above, your Card component will have padding and a white background by default. You can override these styles when...
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