Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test ids for bars in ResponsiveBar #2547

Open
jean-maradjx opened this issue Mar 21, 2024 · 1 comment
Open

Test ids for bars in ResponsiveBar #2547

jean-maradjx opened this issue Mar 21, 2024 · 1 comment

Comments

@jean-maradjx
Copy link

Hi! Could someone provide some examples how to add a test id to the bars or a bar graph?
I tried using the layers option but that removes the tooltip and onClick behavior, I'm guessing I would have to pass it again somehow.

<ResponsiveBar
          layers={[
            'grid',
            'markers',
            ({ bars }) => (
              <>
                {bars.map((bar) => (
                  <g key={bar.key} transform={`translate(${bar.x},${bar.y})`}>
                    <rect
                      width={bar.width}
                      height={bar.height}
                      fill={bar.color}
                      data-testid={`existing-bar-${bar.data.index}`}
                      rx="4"
                      ry="4"
                      strokeWidth="0"
                      focusable="false"
                    />
                  </g>
                ))}
              </>
            ),
            'axes',
            'legends',
          ]}
          .....
@plouc
Copy link
Owner

plouc commented May 1, 2024

This is currently not supported, but you could customize the barComponent, in order to maintain the existing feature, you might want to check the default implementation: https://github.com/plouc/nivo/blob/master/packages/bar/src/BarItem.tsx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants