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

[Labs] Listen to query on select components #1353

Merged
merged 5 commits into from
Jul 28, 2017

Conversation

llorca
Copy link
Contributor

@llorca llorca commented Jul 17, 2017

  • Consumers can use inputProps.onChange to listen to the query without controlling inputProps.value

@llorca llorca requested a review from giladgray July 17, 2017 20:36
@blueprint-bot
Copy link

Listen to query on select components

Preview: documentation
Coverage: core | datetime

const query = e.currentTarget.value;
this.setState({ query, isOpen: !(query.length === 0 && this.props.openOnKeyDown) });
this.setState({ query, isOpen: !(query.length === 0 && openOnKeyDown) });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little tricky to parse mentally. I'd vote for query.length > 0 || !openOnKeyDown).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unrelated, but happy to make the change

@@ -172,9 +173,9 @@ export class Omnibox<T> extends React.Component<IOmniboxProps<T>, IOmniboxState<
private maybeRenderMenu(listProps: IQueryListRendererProps<T>) {
if (this.state.query.length > 0) {
return (
<ul className={CoreClasses.MENU} ref={listProps.itemsParentRef}>
<Menu ulRef={listProps.itemsParentRef}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to the onChange changes, or is this unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, I apparently forgot to do that in a previous PR

@blueprint-bot
Copy link

Tweak query change predicate

Preview: documentation
Coverage: core | datetime

{...tagInputProps}
inputProps={defaultInputProps}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving this line does not feel correct as it prevents changing any of the fields defined in defaultInputProps. why did you do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, you're absolutely right.

const query = e.currentTarget.value;
this.setState({ query, isOpen: !(query.length === 0 && this.props.openOnKeyDown) });
this.setState({ query, isOpen: query.length > 0 || !openOnKeyDown });
Utils.safeInvoke(tagInputProps.inputProps.onChange, e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ not safe yet, if tagInputProps is {} then inputProps is undefined => error.
gotta add a check that tagInputProps.inputProps exists.

@@ -248,8 +248,9 @@ export class Select<T> extends React.Component<ISelectProps<T>, ISelectState<T>>
Utils.safeInvoke(popoverProps.popoverWillClose);
}

private handleQueryChange = (event: React.FormEvent<HTMLInputElement>) => {
this.setState({ query: event.currentTarget.value });
private handleQueryChange = (e: React.FormEvent<HTMLInputElement>) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer calling it event, like it was. (see changes above, where param is still called event)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, was just trying to stay consistent with previous feedback from @adidahiya: #1275 (comment)
What do you think? Happy to change back to event across labs, let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e makes sense for the no-conflict window.event argument. all i care about is consitency

@blueprint-bot
Copy link

Check that inputProps is defined

Preview: documentation
Coverage: core | datetime

@blueprint-bot
Copy link

restProps, e -> event

Preview: documentation
Coverage: core | datetime

@@ -190,6 +199,7 @@ export class Omnibox<T> extends React.Component<IOmniboxProps<T>, IOmniboxState<

private handleQueryChange = (event: React.FormEvent<HTMLInputElement>) => {
this.setState({ query: event.currentTarget.value });
Utils.safeInvoke(this.props.inputProps.onChange, event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotta make sure inputProps exists before you reference it here. or do the { inputProps = {} } deconstruction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha yeah, I always forget. Would be nice to be able to set defaultProps on those generic components!

@@ -250,6 +258,7 @@ export class Select<T> extends React.Component<ISelectProps<T>, ISelectState<T>>

private handleQueryChange = (event: React.FormEvent<HTMLInputElement>) => {
this.setState({ query: event.currentTarget.value });
Utils.safeInvoke(this.props.inputProps.onChange, event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again must make sure inputProps exists before dereferencing it.

@blueprint-bot
Copy link

Check existence of inputProps

Preview: documentation | landing | table
Coverage: core | datetime

@llorca
Copy link
Contributor Author

llorca commented Jul 27, 2017

@cmslewis ready for review again when you get a chance

Copy link
Contributor

@cmslewis cmslewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@giladgray giladgray merged commit bc5f5c2 into master Jul 28, 2017
@giladgray giladgray deleted the al/omnibox-query-listener branch July 28, 2017 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants