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

Amji fixes #1827

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 37 additions & 2 deletions source/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type Props = {

/** Width of list */
width: number,

/** Click handler for items in the list */
onClick?: (index: number) => void,
};

export default class List extends React.PureComponent<Props> {
Expand All @@ -108,6 +111,9 @@ export default class List extends React.PureComponent<Props> {
scrollToAlignment: 'auto',
scrollToIndex: -1,
style: {},
// onClick: () => {
// console.log('List item clicked');
// },
};

Grid: ?React.ElementRef<typeof Grid>;
Expand Down Expand Up @@ -216,7 +222,7 @@ export default class List extends React.PureComponent<Props> {
isVisible,
key,
}: CellRendererParams) => {
const {rowRenderer} = this.props;
const {rowRenderer, onClick} = this.props || {};

// TRICKY The style object is sometimes cached by Grid.
// This prevents new style objects from bypassing shallowCompare().
Expand All @@ -230,14 +236,43 @@ export default class List extends React.PureComponent<Props> {
style.width = '100%';
}

return rowRenderer({
// return rowRenderer({
// index: rowIndex,
// style,
// isScrolling,
// isVisible,
// key,
// parent,
// });

// Assuming each rowRenderer returns a clickable item
const clickableRow = rowRenderer({
index: rowIndex,
style,
isScrolling,
isVisible,
key,
parent,
});

// Check if clickableRow is a valid React element
if (React.isValidElement(clickableRow)) {
// Clone the element and add onClick handler
const clickableItemWithOnClick = React.cloneElement(clickableRow, {
onClick: onClick
? () => {
onClick(rowIndex);
}
: () => {
console.log(`#${rowIndex} List item clicked`);
},
});

return clickableItemWithOnClick;
}

// Handle the case where rowRenderer returns null or an invalid value
return null;
};

_setRef = (ref: ?React.ElementRef<typeof Grid>) => {
Expand Down