ember-power-select icon indicating copy to clipboard operation
ember-power-select copied to clipboard

Prevent Keyboard opening on Android

Open Haidy777 opened this issue 10 years ago • 10 comments

Is there a way to prevent the opening / focusing of the keyboard when the dropdown is opened (and has a Searchfield)?

Problem: If you have a list with a searchfield and only want to tap on entry three (which might be behind the keyboard) you can't do so unless you close the keyboard or scroll through the list.

Haidy777 avatar Jul 21 '16 13:07 Haidy777

Actually yes. That functionality is in the beforeOptionsComponent (https://github.com/cibernox/ember-power-select/blob/master/addon/components/power-select/before-options.js#L12).

You can make a custom beforeOptionsComponent that extends from the default one

import BeforeOptionsComponent from 'ember-power-select/components/components/power-select/before-options';

export default BeforeOptionsComponent.extend({
  focusInput() {
    if (isMobile){
      return;
    }
    this._super(...arguments);
  }
});

That action is not entirely public API, but maybe I should provide a blessed path do do that.

cibernox avatar Jul 21 '16 14:07 cibernox

Any idea how this could be configurable by the user without an very contrived option like focusSearchOnOpen=false?

cibernox avatar Jul 21 '16 14:07 cibernox

Well, I can't find something better ;) . focusSearchOnOpen Would, at least, describe what is does.

Haidy777 avatar Jul 21 '16 14:07 Haidy777

I'm thinking that with contextual component, it could be a configuration on the beforeOptions component.

{{#power-select 
  options=options 
  selected=selected 
  beforeOptionsComponent=(component "power-select/before-options" autofocus=isDesktop) 
  as |opt|}}
  {{opt}}
{{/power-select}}

That way you don't need to create your custom component, just use the default customized with one property. It still adds one config option, but at least it lives where it's useful and the parent component doesn't need to worry about forwarding it. Beside, that wouldn't work in multiple select.

What do you think if this approach?

cibernox avatar Jul 21 '16 14:07 cibernox

That looks good to me, since its relatively easy to use and doesn't blow up the API with things that might be the lesser use case.

Also it shouldn't be that hard to implement, or am I missing a thing here? (Should be a simple if here: https://github.com/cibernox/ember-power-select/blob/master/addon/components/power-select/before-options.js#L12)

Haidy777 avatar Jul 21 '16 15:07 Haidy777

Correct, a simple if (this.get('autofocus')){ ... } there. Do you want to PR it? I han have it published today.

cibernox avatar Jul 21 '16 15:07 cibernox

With a test, to make sure a refactor doesn't remove this functionality. And one [ENHANCEMENT] entry in the changelog.

cibernox avatar Jul 21 '16 15:07 cibernox

Of course, but I won't get it done till tomorrow, since I'm out of office for today. If thats ok for you?

Haidy777 avatar Jul 21 '16 15:07 Haidy777

Sure.

cibernox avatar Jul 21 '16 15:07 cibernox

Thanks.

Haidy777 avatar Jul 22 '16 08:07 Haidy777