calendar icon indicating copy to clipboard operation
calendar copied to clipboard

[Safari][RangeCalendar] Date input switch does not work as expected

Open BionBit opened this issue 6 years ago • 0 comments

STR:

  1. Click on the start date input
  2. Click on the end date input
  3. Notice that you cannot focus back again on the start input

Behavior can be observed here, https://react-component.github.io/calendar/examples/antd-range-calendar.html

Proposed fix - disable setSelectionRange on safari (tested locally),

+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
...
componentDidUpdate() {
    - if (dateInputInstance && this.state.hasFocus && !this.state.invalid &&
    -     !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
    -     dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
    + if (!isSafari) { // Exclude safari, since it has a bug with setSelectionRange
    +  if (dateInputInstance && this.state.hasFocus && !this.state.invalid &&
    +   !(cachedSelectionStart === 0 && cachedSelectionEnd === 0)) {
    +        dateInputInstance.setSelectionRange(cachedSelectionStart, cachedSelectionEnd);
    +    }
    }
}

Question - Do we even need setSelectionRange? Does anyone use it?

BionBit avatar Dec 02 '19 17:12 BionBit