-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(dropdown.tsx): Add originalText prop on Dropdown component #437
Conversation
@@ -2,7 +2,7 @@ import { DropdownItem } from "./types"; | |||
|
|||
export const filterListByKeyword = (list: DropdownItem[], keyword: string): DropdownItem[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this:
export const filterListByKeyword = (list: DropdownItem[], keyword: string): DropdownItem[] => {
const keywordLower = keyword.toLowerCase();
return list.reduce<DropdownItem[]>((filteredItems, item) => {
const { items, label, originalText } = item;
// If the item has sub-items, filter them recursively
if (items?.length) {
const filteredSubItems = filterListByKeyword(items, keyword);
if (filteredSubItems.length) {
filteredItems.push({ ...item, items: filteredSubItems });
}
}
// Check for keyword match in label or originalText
const hasLabelMatch = typeof label === "string" && label.toLowerCase().includes(keywordLower);
const hasOriginalTextMatch = originalText?.toLowerCase().includes(keywordLower);
if (hasLabelMatch || hasOriginalTextMatch) {
filteredItems.push(item);
}
return filteredItems;
}, []);
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me it seems like the original fn doesn't work as expected :/ You search for category and it doesn't return any results even if it has items named "category" :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure which is the wanted functionality here. The "Category" is not an option on the list but the title of the sub-menu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't have clear specs here. lets leave it as is.
# [5.36.0](v5.35.3...v5.36.0) (2024-10-18) ### Features * **dropdown.tsx:** Add originalText prop on Dropdown component ([#437](#437)) ([7c52136](7c52136))
🎉 This PR is included in version 5.36.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Add originalText optional prop on Dropdown component.
The purpose of this prop is the ability to have search functionality when the label is JSX Element.
The component will search and return the matches for
originalText
.