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

[AutoComplete] TextField lost focus when options show on Firefox #2432

Closed
misty000 opened this issue Dec 8, 2015 · 7 comments
Closed

[AutoComplete] TextField lost focus when options show on Firefox #2432

misty000 opened this issue Dec 8, 2015 · 7 comments
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@misty000
Copy link

misty000 commented Dec 8, 2015

event : Object { type: "focusout", timeStamp: 0, jQuery21405151968410568655: true, originalEvent: Object, isDefaultPrevented: $(), which: 0, view: Window → ac1.html, target: <input#mui-id-0>, relatedTarget: null, eventPhase: 1, … } 
event.target : <input type="text" data-reactid=".0.0.0.2" style="did-flip:true;tap-highlight-color:rgba(0,0,0,0);padding:0;position:relative;width:100%;height:100%;border:none;outline:none;background-color:transparent;color:rgba(0, 0, 0, 0.87);font:inherit;" value="" id="mui-id-0">

event : Object { type: "focusin", timeStamp: 0, jQuery21405151968410568655: true, originalEvent: Object, isDefaultPrevented: $(), which: 0, view: Window → ac1.html, target: <a>, relatedTarget: null, eventPhase: 1, … } 
event.target : <a data-reactid=".0.1.$=1$dropDownMenu.0.0.1:$/=1$0.$0.0" type="button" tabindex="0" style="did-flip:true;border:10px;background:none;box-sizing:border-box;display:block;font:inherit;font-family:Roboto, sans-serif;tap-highlight-color:rgba(0, 0, 0, 0);cursor:pointer;text-decoration:none;outline:none;color:rgba(0, 0, 0, 0.87);font-size:16px;line-height:48px;position:relative;transition:all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;white-space:nowrap;">

And on MS Edge and chrome, it's ok.

@misty000
Copy link
Author

misty000 commented Dec 8, 2015

I change (auto-complete.jsx line:222) TextField 's onBlur from

onBlur={() => {
   if (this.focusOnInput && this.state.open)
    this.refs.searchTextField.focus();
  }}

to

onBlur={() => {
  if (this.focusOnInput && this.state.open) {
    this.refs.searchTextField.focus();
    var _refs = this.refs;
    setTimeout(function() {
      _refs.searchTextField.focus();
    }, 0);
  }
}}

then it works.

@alitaheri
Copy link
Member

@oliviertassinari What do think about this fix?

Although I'd go with:

onBlur={() => {
  if (this.focusOnInput && this.state.open) {
    const refs = this.refs;
    setTimeout(() => {
      if (refs.searchTextField) {
        refs.searchTextField.focus();
      }
    }, 0);
  }
}}

It's a lot safer.

@oliviertassinari
Copy link
Member

Hum, why is this blur event triggered in the first place?

@yongxu
Copy link
Contributor

yongxu commented Dec 9, 2015

@oliviertassinari blur event triggered every time menu pops. The menu will take the focus when it updates, which defocus the text input. This wasn't a perfect solution and I was planning to change it in the future.

I suggest we should remove the onBlur eventually, which the nicer solution might be adding props in menus. I am quite busy this week, but I can work it out in 2 weeks if this hasn't resolved yet.

This probably also related to #2418

@oliviertassinari
Copy link
Member

@yongxu Thanks for the extra bit of imformation.
The setTimeout seems to work but, IMHO, it's a hack and not viable.
We should solve this properly.
This is an intent to do so: #2338.

@alitaheri alitaheri modified the milestone: 0.14.0 Release Dec 9, 2015
@oliviertassinari oliviertassinari removed this from the 0.14.0 Release milestone Dec 22, 2015
@konoufo
Copy link

konoufo commented Jun 27, 2016

Hey guys. Did this get resolved at some point ?

@oliviertassinari oliviertassinari changed the title AutoComplete's TextField lost focus when options show on Firefox [AutoComplete] TextField lost focus when options show on Firefox Sep 18, 2016
@oliviertassinari
Copy link
Member

Closed by #4783

@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

5 participants