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

Autofocus don't work with position: fixed #324

Closed
ovk opened this issue Jul 26, 2017 · 14 comments
Closed

Autofocus don't work with position: fixed #324

ovk opened this issue Jul 26, 2017 · 14 comments

Comments

@ovk
Copy link

ovk commented Jul 26, 2017

Expected behavior

It is possible to configure terminal to have focus on initialization, so there's no need to click on it.

Actual behavior

It appears like there's no easy way to achieve this.

@jcubic
Copy link
Owner

jcubic commented Jul 26, 2017

There is enabled option which if it's set to true make terminal enabled, it do that by default but not on Android where you need to manually focus in input to have virtual keyboard open.

@ovk
Copy link
Author

ovk commented Jul 26, 2017

With this sample code, the terminal still doesn't get a focus on loading.
I also tried calling focus() and enable() from within onInit callback, but it has no effect as well.

var consoleBlock = $('.console-block');
consoleBlock.terminal(function (command)
{
    if (command !== '')
    {
        var result = window.eval(command);
        if (result != undefined)
        {
            this.echo(String(result));
        }
    }
},
{
    name: 'test',
    prompt: '> ',
    exit: false,
    memory: true,
    enabled: true
});

@jcubic
Copy link
Owner

jcubic commented Jul 26, 2017

Do you have a demo somewhere because my demos are working. Also what browser/os you're using?

@ovk
Copy link
Author

ovk commented Jul 26, 2017

I'll try to create a minimal demo. Though, if it's working for you, maybe one of the styles or code in my project interfering with jquery.terminal.
Meanwhile, the browser I use is latest Chrome, and OS is Ubuntu 16.04.

@ovk
Copy link
Author

ovk commented Jul 26, 2017

I finally narrowed the issue down to this example: https://jsfiddle.net/txgg52fa/.
It's that terminal style that apparently kills autofocus, if you remove it - it starts working.

@jcubic
Copy link
Owner

jcubic commented Jul 27, 2017

Weird, will check it out.

@jcubic
Copy link
Owner

jcubic commented Jul 27, 2017

I completely don't know why it don't work, I've try to add wrapper that have position: relative inside terminal but this don't work, the only hack I've found is after you create terminal you run this:

setTimeout(function() {
    term.enable();
}, 100);

For some reason the terminal get disabled after init, will check this later today.

@ovk
Copy link
Author

ovk commented Jul 27, 2017

Thanks, I can use this workaround for now. Even this works:

setTimeout(function() {
    term.enable();
}, 0);

@jcubic
Copy link
Owner

jcubic commented Jul 27, 2017

Founded the issue and fixed it in devel branch (but the tests are still broken from other changes)

The other solution (that will work on 1.5.0 version) is to wrap the terminal in container that will have position: fixed https://jsfiddle.net/txgg52fa/1/

@jcubic
Copy link
Owner

jcubic commented Jul 27, 2017

note that position: fixed on terminal if the terminal is not 100% height and width will break the terminal because other elements inside rely on position: relative of the terminal.

@ovk
Copy link
Author

ovk commented Jul 27, 2017

Is the workaround with wrapping terminal inside a fixed container works for you? Because when I open https://jsfiddle.net/txgg52fa/1/ it doesn't seem to autofocus.

@jcubic
Copy link
Owner

jcubic commented Jul 27, 2017

Yes, you're right it don't work, also I was mistaken position: fixed work the same as position: relative for elements inside with position: absolute. the fix will be in 1.5.1.

@ovk
Copy link
Author

ovk commented Jul 27, 2017

Thanks @jcubic. I'll just use setTimeout workaround for now.

@jcubic jcubic changed the title Add autofocus option Autofocus don't work with position: fixed Jul 28, 2017
@jcubic
Copy link
Owner

jcubic commented Jul 29, 2017

The fix is in master in version 1.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants