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: 15752 invalid tooltip on hovering the select component #15788

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mHuzefa
Copy link
Contributor

@mHuzefa mHuzefa commented Feb 20, 2024

Closes #15752

Fixed the invalid title/no title in Select component on hovering

New

  • selectDefaultTitle which gets select element by it's id. if defaultValue is passed, it gets the option with defaultValue from select, otherwise get option by using the selectedIndex

Changed

  • To show the valid tooltip replaced select value with option's text by using selectedIndex in select.options
  • To show default option's text in title executed the selectDefaultTitle in useEffect
  • Added a new test case which is 'should show SelectItem text as title' which renders Select with defaultValue 'Option 2', expected result should be the title 'Option 2'

Testing / Reviewing

  • Hover on Select component, it should show the selected Option as tooltip
  • If there's no option selected, tooltip should not show

@mHuzefa mHuzefa requested a review from a team as a code owner February 20, 2024 17:58
Copy link
Contributor

github-actions bot commented Feb 20, 2024

DCO Assistant Lite bot All contributors have signed the DCO.

@mHuzefa
Copy link
Contributor Author

mHuzefa commented Feb 20, 2024

I have read the DCO document and I hereby sign the DCO.

@mHuzefa
Copy link
Contributor Author

mHuzefa commented Feb 20, 2024

recheck

Copy link

netlify bot commented Feb 20, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 397ac89
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/65eb17f925a73e000844d9b3
😎 Deploy Preview https://deploy-preview-15788--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.

@mHuzefa
Copy link
Contributor Author

mHuzefa commented Feb 21, 2024

@alisonjoseph and @guidari, PR is ready for review. Thanks 😊

Copy link
Contributor

@guidari guidari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀 Thanks for the contribution!
Could you also change the Select.stories.js for the SelectItem components values to match "option-2" instead of "Option 2"

Uploading Screenshot 2024-02-26 at 08.42.50.jpg…

@andreancardona
Copy link
Contributor

@mHuzefa Hii :) thank you for contributing, is there a way you can fix the merge conflicts? Thank you!

@mHuzefa
Copy link
Contributor Author

mHuzefa commented Feb 27, 2024

@guidari Have changed the values to match what you suggested.

@andreancardona I have resolved the merged conflicts although I am sorry that I forgot to rebase my main with upstream and all commits came in this branch so I had to forced push to rewrite the changes. That's why it added other reviewers too.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this - I have a couple suggestions

) as HTMLSelectElement | null;
if (defaultValue) {
const defaultOption: HTMLOptionElement | null | undefined =
selectElement?.querySelector(`option[value=${defaultValue}]`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to declaratively get the value from children instead of using this imperative selector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tay1orjones, removed the imperative selector as I realized it was not needed since we could get value through selectedIndex

@@ -255,6 +272,10 @@ const Select = React.forwardRef(function Select(
size: 'mini',
});
}
useEffect(() => {
selectDefaultTitle(defaultValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be in a function, just place the code directly in the useEffect. It'll be easier to maintain this way being all in once place and not having to scroll up to find the function definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +266 to +267
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to run on every render of the component? If so, I don't think it needs to be in a useEffect. If the select has a ref on it, can we use the ref to get the selected index/element instead of using document.getElementById?

We have a mergeRefs helper function that can be used to combine the forwarded ref and a local ref inside the component for this use if it's needed.

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

Successfully merging this pull request may close these issues.

[Bug]: Select component on hover shows invalid title/tooltip
6 participants