diff --git a/packages/grafana-ui/src/components/Table/FilterList.tsx b/packages/grafana-ui/src/components/Table/FilterList.tsx index 308b4d7f575..0867631fe93 100644 --- a/packages/grafana-ui/src/components/Table/FilterList.tsx +++ b/packages/grafana-ui/src/components/Table/FilterList.tsx @@ -1,7 +1,7 @@ import { css, cx } from '@emotion/css'; import { useCallback, useMemo } from 'react'; import * as React from 'react'; -import { FixedSizeList as List } from 'react-window'; +import { FixedSizeList as List, ListChildComponentProps } from 'react-window'; import { GrafanaTheme2, formattedValueToString, getValueFormat, SelectableValue } from '@grafana/data'; @@ -190,20 +190,11 @@ export const FilterList = ({ height={height} itemCount={items.length} itemSize={ITEM_HEIGHT} + itemData={{ items, values: selectedItems, onCheckedChanged, className: styles.filterListRow }} width="100%" className={styles.filterList} > - {({ index, style }) => { - const option = items[index]; - const { value, label } = option; - const isChecked = values.find((s) => s.value === value) !== undefined; - - return ( -
- -
- ); - }} + {ItemRenderer}
@@ -225,6 +216,27 @@ export const FilterList = ({ ); }; +interface ItemRendererProps extends ListChildComponentProps { + data: { + onCheckedChanged: (option: SelectableValue) => (event: React.FormEvent) => void; + items: SelectableValue[]; + values: SelectableValue[]; + className: string; + }; +} + +function ItemRenderer({ index, style, data: { onCheckedChanged, items, values, className } }: ItemRendererProps) { + const option = items[index]; + const { value, label } = option; + const isChecked = values.find((s) => s.value === value) !== undefined; + + return ( +
+ +
+ ); +} + const getStyles = (theme: GrafanaTheme2) => ({ filterList: css({ label: 'filterList',