Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

New API proposal #44

Open
Open
@edygar

Description

@edygar

I've just read your complain on twitter, and inspired by react-radio-group, I've come up with the following API:

<AutoComplete
  onSelect={doSomething}
  onSearchTermChange={(query, next)=> queryOptions(query).then(next) }
  children={(state, controls)=>
    /*
      `controls` provides callbacks to control AutoComplete, such as setQuery,
      unfocusOption, focusNextOption and focusPrevOption. Also, it can provide the
      `navigateByKeyboad`, which will handle the up and down keys and enter.

      unfocusOption, will unfocus the current focused option.
    */
    <input
      type="search"
      name="query"
      value={state.query}
      onChange={controls.setQuery}
      onKeyPress={controls.navigateByKeyboard}
    />
    { state.async && state.isLoading? <LoadingIcon />:

      {/* `Popup` is a dumb vendor component */}
      <Popup>
        {state.options?
          state.options.map(({option, state, controls})=>
            <div
              key={option.id}
              {/*
                `controls` here could have the AutoComplete `controls` bound to
                current option, such as focusOption, focusNextOption, focusPrevOption,
                selectOption, all with no arguments, so it can be event callbacks
              */}
              onClick={controls.select}
              onMouseEnter={controls.focus}
              onMouseLeave={controls.unfocus}

              className={(state.isFocused? "focused ":"")+(state.isSelected? "selected": "")}

              {/* `option`  could be of any type */}
              children={option.value} 
            />
          )
        :`No valid options for ${query}.`}
      </Popup>
    }
}/>

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions