toddler.dropdown
*dropdown*
dynamic
Dropdown context. Used by Input, Options and Popup to apply logic from use-dropdown hook context
Input
Component will render input DOM element using handlers and values from use-dropdown hook provided by dropdown context.
Options
Component will render options DOM elements using handlers and values from use-dropdown hook provided by dropdown context.
Popup
Component will render popup element using handlers and values from use-dropdown hook provided by dropdown context.
use-dropdown
(use-dropdown {:keys [value options on-change onChange new-fn search-fn area area-position disabled read-only context-fn], :or {search-fn str, context-fn (constantly nil)}})
Abstracts dropdown mechanincs. Expects options prop that holds available options for dropdown, value and on-change callback that will be called with actual value of selected option.
Optional:
- search-fn - will be applied to options to display string representation
- new-fn - when provided will be called when search-fn doesn’t match any of available options
Hook will return map with following state and handler keys:
- search - value that should be displayed in input
- value - actual value
- opened - true|false if dropdown is opened
- options - dropdown options
- focus - when called will focus option
- cursor - position of selected value
- input - reference that you should add to input element
- area - reference that you should add to dropdown element
- search-fn - function that will be used to compute how to display options. Should return string
- ref-fn - function that should be provided to option :ref. So that focus can be called to scroll into view selected option
- read-only true|false
- discard! - when called will reset dropdown
- toggle! - open|closes dropdown
- open! - opens dropdown
- close! - closes dropdown
- select! - will call on change for value
- popup - reference that should be passed to popup element
- on-change - Should be passed to input element
- on-key-down - Should be passed to input element