zestia / ember-select-box

:capital_abcd: A faux select box for Ember apps
MIT License
64 stars 14 forks source link

Add focus-in event handling on the sb.input #6

Closed lessless closed 8 years ago

lessless commented 8 years ago

This PR adds a focus-in handling for the sb.input. Possible use-case is a data preloading before user started typing.

amk221 commented 8 years ago

Thank you very much for this, but could you use {{select-box on-focus-in=preloadThings}} instead? That should work, although I need to document it.

edit: You can also use {{sb.input focus=doSomething}} but due to Ember's attrs proxy that will wipe out any existing focus() functionality

lessless commented 8 years ago

Hm,

there is a weird thing with on-focus-in - it throws an exception inside jQuery focus-in handler when receives same argument ason-search does: on-focus-in = attrs.on-search, but working fine with component action on-focus-in=(action 'preloadThings')

Anyways, problems seem to be solved, but I will really appreciate if you can give more context about the suggestion in the edit.

update: there is a subtle nuance - if I just perform search and set availableThings to the array of returned entities there is a need to call sb.open(); in the on-focus-in handler for wrapper div to obtain is-open class. Otherways it will have only is-focused despite the fact that it actually displays the results.

amk221 commented 8 years ago

For anybody interested the behaviour that @lessless required can be found here.

TLDR; You must preventDefault on mouseDown if you don't want focus to be lost