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.

Add Display Name to CSS classNames for Easy Debugging

See original GitHub issue

Opening a separate issue as requested by @hendrikniemann in https://github.com/chakra-ui/chakra-ui/issues/211.

It would be very helpful if chakra-ui adds component names to CSS classes it generates, like styled-components does. So that we can see components names not only in react developer tools, but in Elements panel as well.

ATM it looks like this: image and it’s very hard to understand anything.

If it’s Flex-css-5vq3nc or Box-css-5vq3nc - it’s at least something.

I’m not sure if we can add names of custom components like styled-components does this, so that

import React from 'react`
import styled from 'styled-components'

const StyledSomething = styled.div`
   display: flex;
`

const CustomComponent = () => <StyledSomething />

export default CustomComponent

becomes CustomComponent-css-5vq3nc.

If it’s possible, it would be super helpful.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
elisherercommented, May 6, 2020

Since babel-plugin-emotion is adding that Contextual Class Names. You can set babel-loader to not exclude @chakra-ui in webpack.config.js in the js loader rule:

  {
        test: /\.js$/,
        exclude: path => !path.includes("@chakra-ui") && /node_modules/.test(path),
        use: "babel-loader",
  }

I tested it and it started to show chakra’s components names in the classNames, but mostly Box and Box-PseudoBox so probably not what you wanted.

2reactions
ljosberinncommented, Oct 23, 2020

you could do this:

import { Box as ChakraBox } from '@chakra-ui/core';

export const Box = ({ className, ...rest }) => <ChakraBox className={['chakra-box', className].filter(Boolean).join(' ')} {...rest} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Naming Conventions that Will Save You Hours of ...
Using the BEM naming convention, element class names are derived by adding two underscores, followed by the element name. For example:
Read more >
Debugging CSS - Learn web development | MDN
Select an element on your page, either by right/ctrl-clicking on it and selecting Inspect, or selecting it from the HTML tree on the...
Read more >
CSS Class Selectors: How to Use to Style an HTML Element
Do you want to stylize HTML elements without hassle? CSS classes will help you do the job! Here, you'll learn how to use...
Read more >
Applying CSS by Component's displayName? - Stack Overflow
Calling all experts! I am trying to add a class to disable all element's descendants to be read only, the style is fine,...
Read more >
Readable Classnames with Styled-Components - Medium
Please note that this articles purpose is to aid in debugging the dom tree when ... Styled-components allow developers to write styles using...
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