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

Editable dropdown caret jumps #1897

Closed
m-tomczyk opened this issue Jan 24, 2017 · 6 comments
Closed

Editable dropdown caret jumps #1897

m-tomczyk opened this issue Jan 24, 2017 · 6 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@m-tomczyk
Copy link

I'm submitting a ... (check one with "x")

[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
(seen on primeng showcase) => http://www.primefaces.org/primeng/#/dropdown

Current behavior

  1. Entering new value into editable dropdown
  2. Changing cursor position in middle of value being entered
  3. Typing again causes one letter to appear in desired place and next cursor jump to the end of input field

Expected behavior

Typing in middle of already entered value keeps cursor in place

  • Browser: Chrome 55 | Firefox 50
@koesper
Copy link

koesper commented May 17, 2017

I've also run into this problem, but haven't been able to fix it yet.
We probably need to do something like this
https://gist.github.com/romuleald/f1b980d5ad01b9f525e8e0244f91711a

@koesper
Copy link

koesper commented May 17, 2017

With some tinkering, I've got it to work, but perhaps someone (@cagataycivici?) will be able to clean up my solution without using a nasty setTimeout

Update onEditableInputChange()
with this code:

onEditableInputChange(event) {
    // save the current cursor position
    let cursorPosition = event.target.selectionStart;
    
    this.value = event.target.value;
    this.updateSelectedOption(this.value);
    this.onModelChange(this.value);

    // set the cursor back to the original position
    setTimeout(()=>{
        event.target.selectionEnd = cursorPosition;
    }, 0);

    this.onChange.emit({
        originalEvent: event,
        value: this.value
    });
}

I'm not quite sure why I need the setTimeout at the moment, I expect I could be able to pass the cursorPosition to the this.onChange, but I havent found where to catch it again.

If you want, I could create a pullrequest, but I don't think my solution is good enough.

@cagataycivici cagataycivici changed the title Editable dropdown input jumps Editable dropdown caret jumps Jun 19, 2017
@cagataycivici cagataycivici self-assigned this Jun 19, 2017
@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Jun 19, 2017
@cagataycivici cagataycivici added this to the 4.1.0 milestone Jun 19, 2017
@cagataycivici
Copy link
Member

Will check for 4.1, thank you.

@koesper
Copy link

koesper commented Jun 28, 2017

@cagataycivici
Copy link
Member

@koesper That is master branch right?

@koesper
Copy link

koesper commented Jun 28, 2017

Yes, with your commit in it. Can you reproduce?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants