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

fix: update Dropdown and MultiSelect to handle interactive labels #18643

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adamalston
Copy link
Contributor

Closes #16987

Updated Dropdown and MultiSelect to handle interactive labels.

Changelog

Changed

  • Updated Dropdown and MultiSelect to handle interactive labels.

Testing / Reviewing

yarn test packages/react/src/components/Dropdown packages/react/src/components/MultiSelect

There seem to be two solutions to this problem:

  1. Call getLabelProps conditionally based on if titleText is an element.
  2. Don't render a label if titleText is an element.

I went with the second approach for two reasons:

  1. Rendering a ToggletipLabel (or any other label element) inside of a label didn't seem like the most logical thing to do.
  2. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#interactive_content

I'm curious to hear others thoughts.

I tried to write a test for these changes. I couldn't get it to pass. I think it has something to do with the changing visibility of the popover and its visibility from the test's perspective. Curious to hear if anyone has suggestions to test these changes. Alternatively, I created Storybook entries.

it('should not steal the focus from interactive elements in titleText', async () => {
  render(
    <Dropdown
      {...mockProps}
      titleText={
        <>
          <ToggletipLabel>Dropdown label</ToggletipLabel>
          <Toggletip>
            <ToggletipButton>Info</ToggletipButton>
            <ToggletipContent>Tooltip content</ToggletipContent>
          </Toggletip>
        </>
      }
    />
  );
  await waitForPosition();

  // Initially, the toggletip content should not be visible
  expect(screen.queryByTestId('toggletip-content')).not.toBeVisible();

  // Click the toggletip button
  await userEvent.click(screen.getByTestId('toggletip-button'));

  // Wait for any asynchronous updates (if needed)
  await waitFor(() => {
    expect(screen.getByTestId('toggletip-content')).toBeVisible();
  });
});

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 44043a3
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-web-components/deploys/67b6b8f9a10a8c000801810b
😎 Deploy Preview https://deploy-preview-18643--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 44043a3
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/67b6b8f97bec230008ab7441
😎 Deploy Preview https://deploy-preview-18643--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 44043a3
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/67b6b8f94ff90d0008ed7993
😎 Deploy Preview https://deploy-preview-18643--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Project coverage is 84.89%. Comparing base (9883920) to head (44043a3).

Files with missing lines Patch % Lines
...ackages/react/src/components/Dropdown/Dropdown.tsx 25.00% 2 Missing and 1 partial ⚠️
...s/react/src/components/MultiSelect/MultiSelect.tsx 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18643      +/-   ##
==========================================
- Coverage   84.92%   84.89%   -0.03%     
==========================================
  Files         408      408              
  Lines       14501    14508       +7     
  Branches     4729     4686      -43     
==========================================
+ Hits        12315    12317       +2     
- Misses       2026     2029       +3     
- Partials      160      162       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

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