daybrush / selecto

Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.
https://daybrush.com/selecto
MIT License
2k stars 81 forks source link

If the mouse is within a selectable node, hitRate doesn't work as expected #152

Open SimeonRolev opened 10 months ago

SimeonRolev commented 10 months ago

Environments

Description

Issue and reproduction

The example from the documentation could be used as a reproduction:

  1. Set hitRate={100}. (the value doesn't actually matter, but 100 is the most obvious for the sake of the example)
  2. Start a dragging selection from outside
  3. The box becomes selected the moment the mouse enters it. It ignores the requirement for 100% coverage. https://codesandbox.io/s/85wdcj

Expected behavior

The box gets selected only if it's fully covered by the blue selection rectangle.

My workaround

selectFromInside={false} doesn't seem to change this. Strangely enough selectByClick={false} seems to fix it, but in that case the regular click-select stops working. So, I did this:

      const [isDragging, setIsDragging] = useState(false);

    /* ... */
        <Selecto
          selectableTargets={[".selectable"]}
          hitRate={100}
          selectByClick={!isDragging}
          onDrag={() => setIsDragging(true)}
          onDragEnd={() => setIsDragging(false)}
          toggleContinueSelect={'shift'}
          onSelect={({ selected }) => {
            setSelection(selected)
          }}
        />

This worked for my case, but seems more like a hack, at least the used properties' names don't state what they actually do. Is there a better way to achieve this?

Thanks!

daybrush commented 8 months ago

@SimeonRolev

selecto's new version is released.