This issue depends on #25252, and was spurred by a discussion happened in #25315 (#25315 (comment) and following comments).
The plan (WIP in #25315) is to make Navigation searchable: typing into a search field would filter the items, keeping only those items that contain the search query.
Normally, NavigationItem is used with a title prop (rendered as item label), so it's just obvious to search on that.
But NavigationItem can also render a custom component, which makes the title not mandatory (and not rendered anyway).
We could search into the custom component's text content, although it could be expensive performance-wise on large navigation lists: for example, we might need to store its ref, or recursively traverse its DOM.
Possibilities to discuss:
-
Require title for custom component items, even if it's not rendered.
- Pros: easy to develop and to consume.
- Cons: counterintuitive to use; inconsistent for the end user if title and content don't match.
-
Add a new keywords prop, to be used simlarly to Blocks keywords. We could search on those if no title is provided, or even in addition to it.
- Pros: precise search results.
- Cons: yet another thing the consumer will need to remember; inconsistent for the end user if keywords and content don't match.
-
Store the custom component ref and search into Node.textContent().
- Pros: easy to develop; consumers wouldn't need to do anything.
- Cons: possibly bad performances; wouldn't work for custom components without text (e.g. images, icons).
-
Traverse recursively through the custom component children.
- Pros: consumer wouldn't need to do anything; we might customize the traversal to pick up non-text content (e.g.
alt attributes).
- Cons: possibly bad performances.
This issue depends on #25252, and was spurred by a discussion happened in #25315 (#25315 (comment) and following comments).
The plan (WIP in #25315) is to make
Navigationsearchable: typing into a search field would filter the items, keeping only those items that contain the search query.Normally,
NavigationItemis used with atitleprop (rendered as item label), so it's just obvious to search on that.But
NavigationItemcan also render a custom component, which makes thetitlenot mandatory (and not rendered anyway).We could search into the custom component's text content, although it could be expensive performance-wise on large navigation lists: for example, we might need to store its
ref, or recursively traverse its DOM.Possibilities to discuss:
Require
titlefor custom component items, even if it's not rendered.Add a new
keywordsprop, to be used simlarly to Blocks keywords. We could search on those if notitleis provided, or even in addition to it.Store the custom component
refand search intoNode.textContent().Traverse recursively through the custom component children.
altattributes).