[Button+] Multiple props are not reponsive
See original GitHub issueDescribe the bug
A couple of props do not work when you give them responsive values
these include the variantColor
and size
props.
Expected Behavior
When the size
prop receives a value of ['md','lg']
it should use the corresponding value at the corresponding breakpoint
To Reproduce check out this sandbox: https://codesandbox.io/s/unresponsive-props-chakra-q4xyf
- Look at the source code
- The button is not displayed at all (both variantColor and size ar ignored as they are arrays), same applies to the ‘direction’ of the stack
Suggested solution(s)
This bug happens because chakra modifies or accesses these values with a function. I use a helper in my projects that makes it possible to also modify responsive arrays and objects and fixes that issue.
function modifyResponsiveValue(value, cb) {
if (typeof value === 'string' || typeof value === 'number') {
return cb(value)
} else if (Array.isArray(value)) {
return value.map(cb)
} else {
const newObj = {}
Object.keys(value).forEach(k => (newObj[k] = cb(value[k])))
return newObj
}
}
Desktop (please complete the following information):
- OS: linux
- Browser chrome
Also happy to make a pr for this after the ts rewrite
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:7
Top Results From Across the Web
How can I pass multiple props in a single event handler in ...
I'm trying to add a onClick listener to a li and the props will be passed to another component that ...
Read more >How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >How to pass multiple props in a single event handler in ...
Method 1: We can make a separate method for the event and call all the props method in that method.
Read more >4 Patterns for Responsive Props in React - DEV Community
Let's say you have different button sizes: large, medium, small. You probably don't want all buttons to change size responsively the same way....
Read more >How to use Props in React - Robin Wieruch
React props are not being passed in Components; React props key is ... it can be confusing for React beginners, because you have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s one way to currently handle responsive button size, using Chakra UI’s
useBreakpointValue()
hook:Still an issue to this date.