react-date-range icon indicating copy to clipboard operation
react-date-range copied to clipboard

Add the possibility to get `selected range label` for `defined range` component

Open atefBB opened this issue 4 years ago • 2 comments

Types of changes

  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description

Add the possibility to get selected range label for defined range component

Related Issue: Solve this prob https://github.com/hypeserver/react-date-range/issues/228

atefBB avatar Nov 04 '21 15:11 atefBB

Hey just wanted to chime in since I also needed this functionality.

In case it's helpful for anyone, you can implement this using the isSelected function on the list of default static ranges (or your own list). For example:

const onChangeHandler = (range) => {
  const knownRange = defaultStaticRanges.find((x) => x.isSelected(range.selection));
  
  if (knownRange) {
    console.log(`Selected known range ${knownRange.label}`)
  } else {
    console.log(`Selected custom range ${range.selection}`)
  }
}

anthonynsimon avatar Nov 05 '21 18:11 anthonynsimon

@anthonynsimon nice shoot! I'll try it ! Thanks.

atefBB avatar Nov 06 '21 05:11 atefBB