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

[Bug]: Adding toggletip to form fields causes label and field misalignment #18169

Open
2 tasks done
silverclaru opened this issue Nov 28, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@silverclaru
Copy link

silverclaru commented Nov 28, 2024

Package

@carbon/react

Browser

Chrome, Firefox

Package version

1.66.0 (but reproducible on 1.71.0 as well)

React version

18.2.0

Description

When adding toggletips to form fields through the labelText prop, styling is slightly different than for form fields without a toggletip.

Image

I'm not sure if labelText is the recommended way of adding a tooltip to a form field. I could not really find guidance for this. If it is the recommended way, it should work (look good) out of the box, I feel like.

Reproduction/example

https://stackblitz.com/edit/github-bimuxr?file=src%2FApp.jsx

Steps to reproduce

The screenshot above was created through the following source code.

import {
  Button,
  FormLabel,
  TextInput,
  Toggletip,
  ToggletipButton,
  ToggletipContent,
} from '@carbon/react';
import { Information } from '@carbon/react/icons';
import React from 'react';

const LabelWithTooltip = (props) => (
  <div>
    <FormLabel>{props.label}</FormLabel>
    {props.tooltip && (
      <Toggletip>
        <ToggletipButton label="Show additional information">
          <Information />
        </ToggletipButton>
        <ToggletipContent>{props.tooltip}</ToggletipContent>
      </Toggletip>
    )}
  </div>
);

export default function App() {
  return (
    <div style={{ padding: '1rem', display: 'flex', gap: '8px' }}>
      <TextInput labelText={<LabelWithTooltip label="Field A" />} />
      <TextInput
        labelText={<LabelWithTooltip label="Field B" tooltip="B's tooltip" />}
      />
    </div>
  );
}

I was made aware that technically the <FormLabel> is not required to get the correct text styling. However, omitting it, leads to the icon being displayed right next to the label and not with some space in between as in the screenshot.

I also did try something like this:

<Stack gap={3}>
    <LabelWithTooltip .../>
    <TextInput .../>
</Stack>

But that still leads to a similar result although the misalignment is more subtle (on my screen 2px vs 4 px).

Suggested Severity

None

Application/PAL

No response

Code of Conduct

@silverclaru silverclaru changed the title [Bug]: Adding toggletip to form fields causes label and field mis-alignment [Bug]: Adding toggletip to form fields causes label and field misalignment Nov 28, 2024
@sstrubberg sstrubberg moved this to 🕵️‍♀️ Triage in Design System Dec 10, 2024
@alisonjoseph alisonjoseph moved this from 🕵️‍♀️ Triage to ⏱ Backlog in Design System Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ⏱ Backlog
Development

No branches or pull requests

2 participants