Jemt / Fit.UI

Fit.UI is a JavaScript based UI framework built on Object Oriented principles
http://fitui.org
GNU Lesser General Public License v3.0
19 stars 7 forks source link

Input (DesignMode): Focused(true) does not work immediately after render #148

Closed FlowIT-JIT closed 2 years ago

FlowIT-JIT commented 2 years ago

Assigning focus to a control should be possible when it is rooted in DOM. However, due to DesignMode's async. initialization, this does not work:

var ed = new Fit.Controls.Input();
ed.DesignMode(true);
ed.Render(document.body);
ed.Focused(true); // Focus must be set AFTER control has been rooted in DOM

The example above does not work - the control does not gain focus. It works as expected for a traditional textarea control:

var ed = new Fit.Controls.Input();
ed.MultiLine(true);
ed.Render(document.body);
ed.Focused(true); // Focus must be set AFTER control has been rooted in DOM

The browser/document must have focus for this to work, naturally.

If the issue is resolved by postponing focused state until editor is ready, then consider whether execution of OnFocus should be async. as well. This behavior will differ from all other components where OnFocus fires immediately when calling Focused(true). EDIT: Actually OnFocus fires async. since it is based on FocusIn. But it fires almost immediately. The best solution is probably to have the control container gain focus temporarily and fire OnFocus immediately. This will also allow for OnBlur to fire as expected if control lose focus again while editor is loading.

FlowIT-JIT commented 2 years ago

Fixed as suggested with commit https://github.com/Jemt/Fit.UI/commit/a95707e00d8cb506f2c7e272fc5f4cfd68c262a1