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

Adding tooltip content option to combobox item #321

Merged
merged 1 commit into from
Nov 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/components/Combobox/__stories__/combobox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ const getOptions = (selectedId, additionalOptions = []) => {
{ id: "1", label: "with left icon", leftIcon: "fa fa-star-o" },
{ id: "2", label: "with right icon", rightIcon: "fa fa-star-o" },
{ id: "3", label: "disabled", disabled: true, rightIcon: "fa fa-star-o" },
{ id: "4", label: "custom left icon", leftIcon: iconRenderer, leftIconType: Combobox.iconTypes.RENDERER },
{ id: "5", label: "custom right icon", rightIcon: iconRenderer, rightIconType: Combobox.iconTypes.RENDERER },
{ id: "6", label: "no icon" },
{ id: "7", label: "with left icon and a very very long name", leftIcon: "fa fa-star-o" },
{ id: "8", label: "with right icon and a very very long name", rightIcon: "fa fa-star-o" }
{
id: "4",
label: "disabled with tooltip",
disabled: true,
tooltipContent: "this option is disable",
rightIcon: "fa fa-star-o"
},
{ id: "5", label: "custom left icon", leftIcon: iconRenderer, leftIconType: Combobox.iconTypes.RENDERER },
{ id: "6", label: "custom right icon", rightIcon: iconRenderer, rightIconType: Combobox.iconTypes.RENDERER },
{ id: "7", label: "no icon" },
{ id: "8", label: "with left icon and a very very long name", leftIcon: "fa fa-star-o" },
{ id: "9", label: "with right icon and a very very long name", rightIcon: "fa fa-star-o" }
].concat(additionalOptions);

options.forEach(option => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const ComboboxOption = ({
selected,
ariaLabel
} = option;
let { tooltipContent } = option;

const ref = useRef(null);
const labelRef = useRef();
Expand Down Expand Up @@ -90,10 +91,13 @@ const ComboboxOption = ({
},
[onOptionClick, index, option]
);
if (!tooltipContent) {
tooltipContent = isOptionOverflowing ? label : null;
}

return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<Tooltip content={isOptionOverflowing ? label : null}>
<Tooltip content={tooltipContent}>
<div
ref={ref}
key={id || label}
Expand Down