-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[select] itemListRenderer #2252
Conversation
menuRenderer => itemListRenderer
add filteredItems to renderer props. itemListRenderer is now the only one with access to renderItem/items/itemsParentRef. the default itemListRenderer produces a Menu using filteredItems (to preserve arrow keys order).
@reiv, your input on this change would be greatly appreciated! |
Merge branch 'develop' of github.com:palantir/blueprint into gg/item-list-rendererPreview: documentation | landing | table |
update docsPreview: documentation | landing | table |
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.
👍 from me. Just have a few minor comments.
* | ||
* The default implementation invokes `itemRenderer` for each item that passes the predicate | ||
* and wraps them all in a `Menu` element. If the query is empty then `initialContent` is returned, | ||
* and if all items are filtered away then `noResults` is returned. |
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.
Nit: "if there are no items that match the predicate" (items
could be empty, for all we know.)
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.
nice
* This is required for the `QueryList` to scroll the active item into view automatically. | ||
*/ | ||
itemsParentRef: (ref: HTMLElement | null) => void; | ||
/** Rendered elements returned from `menuRenderer` prop. */ |
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.
menuRenderer
-> itemListRenderer
@@ -231,6 +269,28 @@ export class QueryList<T> extends React.Component<IQueryListProps<T>, IQueryList | |||
} | |||
} | |||
|
|||
private defaultMenuRenderer = (listProps: IItemListRendererProps<T>) => { |
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.
Would have suggested defaultItemListRenderer
just for consistency, but that's a mouthful isn't it?
|
||
private renderItem = (item: T, index?: number) => { | ||
const { activeItem, query } = this.props; | ||
const matchesPredicate = this.state.filteredItems.indexOf(item) >= 0; |
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.
I know this isn't new, but wouldn't it have been better in hindsight to cache the filtered items as an ES6 Set
(or anything that's not O(N)
, really) to speed up this lookup?
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.
yes, definitely a pain point in my head. we should do such a refactor.
* Helper method for rendering `props.filteredItems`, with optional support for `noResults` | ||
* (when filtered items is empty) and `initialContent` (when query is empty). | ||
*/ | ||
public static renderFilteredItems( |
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.
Can we broaden the scope of this helper? How about instead of taking IItemListRendererProps
, we take items: T[]
; then an itemListRenderer
can call it with either filteredItems
or items
, depending on which is more appropriate. Also, since this is meant to be called first and foremost by an itemListRenderer
, it's a bit awkward that it's defined on QueryList
, which we usually don't import directly when consuming Select
and friends. Can we maybe make it a top-level export of the select
package?
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.
cool yes def down for the root export.
taking the props as a first argument was a quick way to get off the ground, cuz it receives both items and renderItem
in one go. the name indicates which set of items it'll use. my goal here was to streamline the 99% case; if you want to render items
then you're on your own.
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.
Yep, fair enough on the streamlining part.
add common/index.ts
Merge branch 'develop' of github.com:palantir/blueprint into gg/item-list-rendererPreview: documentation | landing | table |
renderFilteredItems tests filePreview: documentation | landing | table |
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.
Overall, I'm not super familiar with this feature, but this refactor seems pretty elegant.
following up from @reiv's excellent work in #2080, this PR moves
menuRenderer
prop toQueryList
and makes its behavior available to allselect
components. it also separate therenderer
props fromitemListRenderer
props, such thatiLR
is the only one who knows aboutrenderItem
and the ref handler.renderer
now receives the rendereditemList
element, which simplifies its logic greatly.menuRenderer
⇒itemListRenderer
to match other prop names (tho this prop hasn't shipped yet, so not breaking)renderFilteredItems
static function is generally useful for ...rendering filtered items.initialContent
,noResults
,itemListRenderer
up toQueryList
props.QueryList
renderer
receives rendereditemList
ReactNode.filteredItems
to renderer props (per Add filteredItems to queryList #2213).itemListRenderer
is now the only one with access torenderItem/items/itemsParentRef
. the defaultitemListRenderer
produces aMenu
usingfilteredItems
(to preserve arrow keys order).listProps.itemList