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]: Interactive elements inside of Dropdown's titleText prop do not work correctly #16987

Open
2 tasks done
jared-schwalbe opened this issue Jul 17, 2024 · 2 comments · May be fixed by #18643
Open
2 tasks done

[Bug]: Interactive elements inside of Dropdown's titleText prop do not work correctly #16987

jared-schwalbe opened this issue Jul 17, 2024 · 2 comments · May be fixed by #18643
Labels
adopter: product Work-stream that directly helps a Product team. component: dropdown package: @carbon/react @carbon/react role: dev 🤖 severity: 3 https://ibm.biz/carbon-severity type: bug 🐛

Comments

@jared-schwalbe
Copy link

Package

@carbon/react

Browser

Chrome

Package version

1.60.3

React version

16.14.0

Description

When using a Toggletip inside of the node passed to the titleText prop of a Dropdown, the Toggletip refuses to open and instead simply passes focus to the Dropdown when clicked.

My use case is that I would like to have a tooltip next to the label for a dropdown and inside that tooltip I want to provide a link to some documentation.

A valid workaround is instead of using the titleText prop on the Dropdown, simply use a FormLabel as a sibling to the Dropdown.

Reproduction/example

https://stackblitz.com/edit/github-c68srd-hwqb9s?file=src%2FApp.jsx&preset=node=

Steps to reproduce

  1. Pass a node to the titleText prop of Dropdown and include a Toggletip inside that node
  2. Click on the Toggletip button

Suggested Severity

None

Application/PAL

No response

Code of Conduct

@tay1orjones
Copy link
Member

tay1orjones commented Jul 17, 2024

Thanks again for bringing this up and opening this, I think you should be able to put interactive elements into titleText and have them work as expected. It looks like the Toggletip contents never shows because focus is immediately being moved to the Dropdown for some reason.

@tay1orjones tay1orjones added severity: 3 https://ibm.biz/carbon-severity and removed status: needs triage 🕵️‍♀️ labels Jul 17, 2024
@tay1orjones tay1orjones moved this to ⏱ Backlog in Design System Jul 17, 2024
@tay1orjones tay1orjones added role: dev 🤖 component: dropdown package: @carbon/react @carbon/react adopter: product Work-stream that directly helps a Product team. labels Jul 17, 2024
@jose-biescas
Copy link

jose-biescas commented Feb 7, 2025

Hi, just happened to encounter this same bug still in v1.75.0

I believe the cause of the bug is because the Dropdown component is utilizing the html element <label> tag to wrap the titleText property. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label from the documentation:

When a user clicks or touches/taps a label, the browser passes the focus to its associated input (the resulting event is also raised for the input). That increased hit area for focusing the input provides an advantage to anyone trying to activate it — including those using a touch-screen device.

This is most likely why, the focus initially is on the Tooltip, but it is quickly overlapped by the label's property of shifting that focus over to the input.

Those lines are here: 613-617

        {titleText && (
          <label className={titleClasses} {...getLabelProps()}>
            {titleText}
          </label>
        )}

Whereas other components like the TextInput re-use the Text component for their labelText.

const label = labelText ? (
    <Text as="label" htmlFor={id} className={labelClasses}>
      {labelText}
    </Text>
  ) : null;

Not sure if there is any difference in these properties or why they are labeled differently, both properties have the same description: Provide the text that will be read by a screen reader when visiting this control

Edit:
Just noticed the Text component has as='label', I can see the input being highlighted first, then the focus shifts to the toggletip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adopter: product Work-stream that directly helps a Product team. component: dropdown package: @carbon/react @carbon/react role: dev 🤖 severity: 3 https://ibm.biz/carbon-severity type: bug 🐛
Projects
Status: ⏱ Backlog
Development

Successfully merging a pull request may close this issue.

3 participants