-
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] new itemDisabled prop #2580
Conversation
`moveActiveIndex` is now recursive and wraps around when reaching top/bottom of list
SelectExample option to disable films before year 2000Preview: documentation | landing | table |
initialContent={initialContent} | ||
noResults={<MenuItem disabled={true} text="No results." />} | ||
onItemSelect={this.handleValueChange} | ||
popoverProps={{ minimal }} | ||
> | ||
<Button rightIcon="caret-down" text={film ? film.title : "(No selection)"} disabled={disabled} /> | ||
<Button | ||
icon="film" |
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.
didn't review the code, but works great and looks great 👍
moveActiveIndex => getNextActiveItem returns TPreview: documentation | landing | table |
required index paramPreview: documentation | landing | table |
@@ -106,4 +120,6 @@ export class SelectExample extends React.PureComponent<IExampleProps, ISelectExa | |||
this.setState(state => ({ ...state, [prop]: checked })); | |||
}; | |||
} | |||
|
|||
private isItemDisabled = (film: IFilm) => this.state.disableItems && film.year < 2000; |
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.
this works because no films were ever produced prior to Jan 1, 1990 😜
return undefined; | ||
} else if (this.isItemDisabled(filteredItems[nextActiveIndex], nextActiveIndex)) { | ||
// keep on moving in given direction if this item is disabled. | ||
return this.getNextActiveItem(direction, nextActiveIndex, startIndex); |
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.
seems a little weird to use recursion on an unbounded list when iterating would suffice
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 found recursion to be the simplest code change here (tho i then went ham on the refactor 🤷♂️)
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.
will refactor to use a loop
I'll note that if you select shawshank then disable items from 1990's, it remains selected. I don't think that's necessarily a bug, but it does mean that if you change the selection, you can't revert to shawshank. |
that's an artifact of the example implementation. selection is purely controlled by the parent. |
half the line count!
break recursion with a do/whilePreview: documentation | landing | table |
Changes proposed in this pull request:
itemDisabled: keyof T | (T => boolean)
prop allows disabling items in the list!