react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Select an option onMouseUp

Open calesce opened this issue 11 years ago • 6 comments

I believe this is a common "gesture", but I commonly use select elements like this: click + drag + navigate to element + mouse-up, which would select that element.
This is enabled in the native <select>, but doesn't seem supported in the examples, where selecting elements requires a second click. Also, with this gesture, there is slightly different behavior between Chrome and the other browsers (haven't tested IE). In Chrome, the click + drag + mouse-up behavior closes the options list, while in FF/Safari, the list stays open.
Would this PR be accepted?

calesce avatar Jul 05 '15 02:07 calesce

I agree with this calesce, it's a natural behaviour to click to open list, then click+drag whilst selecting option. Mouse up selects the item.

sambomartin avatar Aug 12 '15 11:08 sambomartin

Not sure if this has been brought up elsewhere but I was searching for this because it's important to me as well! This is a very common behavior and at least in 0.9.1 the result (not selecting the value hovered over) is unexpected.

nickyhajal avatar Oct 19 '16 15:10 nickyhajal

Will reopen if necessary, please comment if this is still an issue.

jossmac avatar Sep 21 '18 06:09 jossmac

This is still an issue - select2 implements this native behavior of being able to drag the mouse to select an item, but react-select still does not.

as-com avatar Jun 29 '20 15:06 as-com

Greetings, and apologies that no collaborators has replied as of yet.

From the title, I had initially assumed that the ask was for click & drag multi-select, but It would appear that the ask instead is to have the option selected onMouseUp instead of onClick, is that correct?

@as-com This is possible by creating a custom Option component. By overwriting the innerProps, it is possible to remove the onClick handler and instead add a onMouseUp event handler.

const Option = (props) => {
  const { onClick, ...restInnerProps } = props.innerProps;
  const onMouseUp = () => props.selectOption(props.data);
  const innerProps = {
    ...restInnerProps,
    onMouseUp
  };

  return <components.Option {...props} innerProps={innerProps} />;
};

const App = (props) => {
  return <Select components={{ Option }} {...props} />;
};

Demo: codesandbox

Given that this has been open for over 4.5 years, I think it is safe to close this as resolved via custom component implementation. If anyone else has further questions or concerns, please feel free to reply and happy to discuss further if you have any questions.

ebonow avatar Feb 05 '21 04:02 ebonow

Would be good to have an easier way to have react-select use onMouseUp for everything as it using onMouseDown currently fails WCAG's success criteria 2.5.2 -> https://www.w3.org/WAI/WCAG21/Understanding/pointer-cancellation.html

This really should be fixed.

basickarl avatar Mar 02 '26 09:03 basickarl