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

Input field should not lose focus when clicking on picker #85

Closed
xdev1 opened this issue Oct 7, 2021 · 8 comments
Closed

Input field should not lose focus when clicking on picker #85

xdev1 opened this issue Oct 7, 2021 · 8 comments

Comments

@xdev1
Copy link
Contributor

xdev1 commented Oct 7, 2021

It looks really odd that the input field loses focus for a short moment when you click somewhere on the picker.
This seems to be easily fixable:

  1. In file pickerListeners.js add the following function:
  export function onMouseDownPicker(ev) {
    ev.preventDefault();
  }
  1. In file Picker.js import also onMouseDownPicker and register it:

       ...
    
       import {
         ...
         onMouseDownPicker
       } from '../events/pickerListeners.js';
       
       ...
    
           registerListeners(datepicker, [
              ...
              [element, 'mousedown', onMouseDownPicker],
              ...
           ]);

@mymth Please let me know what you think of this enhancement. I could prepare a PR if you like.

@mymth
Copy link
Owner

mymth commented Nov 1, 2021

I din't think seriously to solve it because it's bootstrap-datepicker behavior. But thunks, this seems like giving me a hint for the solution of #78

@xdev1
Copy link
Contributor Author

xdev1 commented Nov 1, 2021

Okay, thanks for the info. This is something that can also be done in userland, in case someone (like me 😉) does not like the above mentioned vanillajs-/bootstrap-datepicker behavior.
So I will close this issue.

@xdev1 xdev1 closed this as completed Nov 1, 2021
@mymth
Copy link
Owner

mymth commented Nov 7, 2021

Sorry, It looks like one of the typos I made made you misunderstand. I meant "I didn't think seriously...", not "I don't think seriously..." So I'm willing to make this change.
I think bootstrap-datepicker's this behavior is not intentional and there's no need to follow.
I'll reopen this for my tracking purpose.

@mymth mymth reopened this Nov 7, 2021
@xdev1
Copy link
Contributor Author

xdev1 commented Nov 7, 2021

@lubomirblazekcz Could you please do me a favor and check whether the little changes mentioned in the issue description above have any negative impact on your time selector extension here: #25 (comment) ?
Many thanks.

[Edit]: I think, for a simple test, just adding datepicker.picker.element.addEventListener('mousedown', (ev) => ev.preventDefault()) should do the same.

@lubomirblazekcz
Copy link

@xdev1 seems to be ok 👍

@lubomirblazekcz
Copy link

@xdev1 ok maybe not after all, but it can be easily fixed

I've created new PR #92 to resolve my issues with timepicker extention

I've edited your code a little to work with that change

pickerListeners.js (maybe !datepicker.inline should be there too, doesn't need to be for inline picker)

export function onMouseDownPicker(datepicker, ev) {
  if (!ev.target.matches(datepicker.config.focusIgnoredSelector)) {
    ev.preventDefault();
  }
}

Picker.js

registerListeners(datepicker, [
    ...
    [element, 'mousedown', onMouseDownPicker.bind(null, datepicker)],
    ...
 ]);

@xdev1
Copy link
Contributor Author

xdev1 commented Nov 11, 2021

@lubomirblazekcz

Wouldn't the following changes work for your time field extension (I think this should also solve #78)? This is only meant as a just-FYI-alternative solution without the need of an additional config parameter focusIgnoredSelector or something. I personally have no preference here.

[Edited several times]

  1. Remove the following lines - I do not think we need them any longer:

    export function onClickPicker(datepicker) {
    if (!datepicker.inline && !datepicker.config.disableTouchKeyboard) {
    datepicker.inputField.focus();
    }
    }


    [element, 'click', onClickPicker.bind(null, datepicker), {capture: true}],

  2. In file pickerListeners.js add the following function:

      export function onMouseDownPicker(datepicker, ev) {
        ev.preventDefault();
       
        if (!datepicker.inline && !datepicker.config.disableTouchKeyboard) {
           datepicker.inputField.focus();
        }
      }
  3. In file Picker.js import also onMouseDownPicker and register it:

       ...
    
       import {
         ...
         onMouseDownPicker
       } from '../events/pickerListeners.js';
       
       ...
    
           registerListeners(datepicker, [
              ...
              [element, 'mousedown', onMouseDownPicker.bind(null, datepicker)],
              ...
           ]);
  4. Now for your time input element you have to do something like:

      timeInputElement.addEventListener('mousedown', (ev) =>
        ev.stopPropagation();
      );

@lubomirblazekcz
Copy link

@xdev1 yeah that works even better, nice. Solves #78 and #92 isn't needed anymore

@mymth mymth closed this as completed in 646d69f Dec 29, 2021
mymth added a commit that referenced this issue Dec 29, 2021
…ng default of mousedown event in order to prevent input field from flickering and give users a way to extend datepicker by adding their own elements (#78)

Close #85, Close #92

* Merge branch 'dev'
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

3 participants