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] Suggest component #1499

Merged
merged 14 commits into from
Aug 29, 2017
Merged

[Labs] Suggest component #1499

merged 14 commits into from
Aug 29, 2017

Conversation

llorca
Copy link
Contributor

@llorca llorca commented Aug 24, 2017

Checklist

  • Include tests
  • Update documentation

Changes proposed in this pull request:

Suggest component composes Popover, InputGroup and QueryList

Screenshot

screen recording google chrome

@llorca llorca requested a review from giladgray August 24, 2017 21:41
@llorca llorca mentioned this pull request Aug 24, 2017
3 tasks
@blueprint-bot
Copy link

Update docs

Preview: documentation
Coverage: core | datetime

const { handleKeyDown, handleKeyUp } = listProps;
const inputValue: string = isTyping
? query : selectedItem
? inputValueRenderer(selectedItem) : "";
Copy link
Contributor

Choose a reason for hiding this comment

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

alignment to clarify double-ternary

const inputValue: string = isTyping
    ? query 
    : (selectedItem ? inputValueRenderer(selectedItem) : "");

onChange={this.handleQueryChange}
/>
</div>
<div onKeyDown={handleKeyDown} onKeyUp={handleKeyUp}>
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't these handlers go on Menu? shouldn't need an extra wrapper element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can have Menu support ul HTML props in a separate PR (and then refactor all the labs components to use that)

<div
onKeyDown={this.getTargetKeyDownHandler(handleKeyDown)}
onKeyUp={this.state.isOpen ? handleKeyUp : undefined}
onClick={this.handleInputClick}
Copy link
Contributor

Choose a reason for hiding this comment

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

can these handlers go on InputGroup? you'll need to invoke corresponding inputProps.on* in each handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try and report back

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

this.input.blur();
this.setState({ isOpen: false });
} else {
this.setState({ isOpen: closeOnSelect ? nextOpenState : true });
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer else if (closeOnSelect) { setState( true ) } instead of the no-op nextOpenState in ternary

Copy link
Contributor

Choose a reason for hiding this comment

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

✅ wait, i think i get it and this code is actually ok. nextOpenState is param so it needs to make it into state somehow, which my suggestion does not allow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by no-op, but your suggestion is not equivalent to what I have.

This logic is messed up anyway, I'm gonna handle closeOnSelect stuff where it belongs: handleItemSelect


if (this.input !== document.activeElement) {
// the input is no longer focused so we can close the popover
this.input.blur();
Copy link
Contributor

Choose a reason for hiding this comment

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

why blur if we already know it's not focused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question, it's because handleItemSelect always refocuses the input. Now it only does with closeOnSelect={false}

private handlePopoverWillClose = () => {
const { popoverProps = {} } = this.props;

// resetting the query when the popover close
Copy link
Contributor

Choose a reason for hiding this comment

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

no resetOnClose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We always reset on close here. If we don't, you can end up with the filtered list desynced from what's shown in the input (because we don't show query in the input at all times)

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha, cool. please update comment to clarify why it always resets.

@dmackerman
Copy link
Contributor

Neat. Will this support InputGroup props so that icons can be applied and such?

@llorca
Copy link
Contributor Author

llorca commented Aug 24, 2017

@dmackerman you bet

@llorca llorca requested a review from giladgray August 24, 2017 22:30
@blueprint-bot
Copy link

Fix errors

Preview: documentation
Coverage: core | datetime

@llorca
Copy link
Contributor Author

llorca commented Aug 24, 2017

Not sure why this commit broke the build... The change is literally one word 🤔

- `Suggest` behaves similarly to `Select`, except it renders a text input as Popover target instead of arbitrary children.
+ `Suggest` behaves similarly to `Select`, except it renders a text input as the `Popover` target instead of arbitrary children.

@giladgray
Copy link
Contributor

yeah not sure about the build... looks suspiciously like a test flake cuz it's about focus. 😕

@llorca
Copy link
Contributor Author

llorca commented Aug 25, 2017

Flaking test:

  <Overlay>
    Focus management
      ✖ returns focus to overlay if enforceFocus=true
        Chrome 60.0.3112 (Mac OS X 10.12.6)
      Error: Uncaught AssertionError: expected <button></button> to not equal <button></button> (test/index.ts:4311)

@giladgray how can I fix that? The underlying Popover has enforceFocus={false} and this test is about enforceFocus={true}:
https://github.com/palantir/blueprint/blob/al/suggest2/packages/labs/src/components/select/suggest.tsx#L138

@llorca
Copy link
Contributor Author

llorca commented Aug 25, 2017

Well that test actually fails on master too...

@blueprint-bot
Copy link

Update docs

Preview: documentation
Coverage: core | datetime

@cmslewis
Copy link
Contributor

@llorca the "Open popover on key down" option doesn't appear to work:

2017-08-25 15 44 44

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.

Bug: openOnKeyDown doesn't appear to work.

@blueprint-bot
Copy link

Set proper state and fix keyDown handler

Preview: documentation
Coverage: core | datetime

@llorca llorca requested a review from cmslewis August 26, 2017 17:05
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.

Looks good overall! Left some questions for future reference.


// reset the query when the popover close, make sure that the list
// isn't filtered on when the popover opens next
this.setState({ query: "" });
this.setState({
activeItem: selectedItem ? selectedItem : this.props.items[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Prefer explicit selectedItem != null. I like to avoid loose falsy checks.

...restProps,
} = this.props;

return <this.TypedQueryList
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typical format for us is:

return (
    // indented component
);

const { isTyping, selectedItem, query } = this.state;
const { ref, ...htmlInputProps } = inputProps;
const { handleKeyDown, handleKeyUp } = listProps;
const inputValue: string = isTyping
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do away with the explicit : string type here?

private handleInputFocus = (event: React.SyntheticEvent<HTMLInputElement>) => {
const { openOnKeyDown, inputProps = {} } = this.props;

this.selectText();
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth adding a selectAllOnFocus: boolean prop like we do for NumericInput?


if (!closeOnSelect) {
this.input.focus();
this.selectText();
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 line necessary even though focus'ing will trigger handleInputFocus and subsequently invoke this.selectText()? (Per the requestAnimationFrame comment above, I'm assuming focus doesn't happen synchronously here?)

@cmslewis cmslewis dismissed giladgray’s stale review August 29, 2017 17:31

All comments appear to be addressed

@cmslewis
Copy link
Contributor

cmslewis commented Aug 29, 2017

@giladgray etc. I'm gonna merge this and then do an audit to make sure controlled mode works as expected before we release. Might even...

(••)
( •
•)>⌐■-■
(⌐■_■) ...write some tests.

EDIT: Eh, actually, I'll just do that here before merging. There are also a couple other things I want to fix that I noticed in a second pass.

@cmslewis cmslewis changed the title [Labs] New Suggest component [Labs] Suggest component Aug 29, 2017
@blueprint-bot
Copy link

Fix param name

Preview: documentation | table
Coverage: core | datetime

@cmslewis
Copy link
Contributor

Brought test coverage up to 90%.

@cmslewis cmslewis merged commit 8398411 into master Aug 29, 2017
@cmslewis cmslewis deleted the al/suggest2 branch August 29, 2017 23:00
@cmslewis cmslewis mentioned this pull request Aug 30, 2017
@sushain97
Copy link
Contributor

If I understand this component correctly, it fulfills #1407 (please feel free to close the issue if I'm right).
@mfedderly, probably worth switching to this to easily get rid of the double input box problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants