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

Mouse up incorrectly triggers select focus and drop down when not in focus. #705

Open
kane81 opened this issue Aug 30, 2024 · 3 comments
Open

Comments

@kane81
Copy link

kane81 commented Aug 30, 2024

  1. Outside of the select component, click the mouse button and hold.
  2. Drag the cursor over the select component and release the mouse button.
  3. The select incorrectly opens up as per images below
  • I tested with a standard select and it does not dropdown on mouse button release.

2024-08-30_11-35-52

This is causing an issue with copy and paste as seen below.
User highlights the number and as the cursor has hovered over select - it steals focus from the number I wanted to copy and expands the select...

2024-08-30_11-45-46

@kane81
Copy link
Author

kane81 commented Sep 3, 2024

Problem code in Select.svelte - on on:pointerup instead of on:click

<div
	class="svelte-select {containerClasses}"
	class:multi={multiple}
	class:disabled
	class:focused
	class:list-open={listOpen}
	class:show-chevron={showChevron}
	class:error={hasError}
	style={containerStyles}
	on:pointerup|preventDefault={handleClick}
	bind:this={container}
	use:floatingRef
	role="none"
>

FYI I fixed the issued by stopping the pointerup event and trigger on the click event. Additionally I added the ability to copy and paste text within a select too.


onMount(() => {
		// fix bug where the original coding for svelte-select uses pointerup event instead of onclick event!
		const selectItem = document.getElementById(id);
		if (selectItem) {
			const container = selectItem.parentNode.parentNode;
			container.addEventListener(
				"pointerup",
				(e) => {
					e.stopPropagation();
				},
				true
			);
			container.addEventListener(
				"click",
				() => {
					// allow selection of text rather than stop selection
					const selectedText = window.getSelection().toString();
					if (!selectedText) {
						listOpen = !listOpen;
					}
				},
				false
			);
		}
	});

@steppenwolfXYZ
Copy link

This is the same as #585 but with easy-to-understand visual explanation. I have the same issue.

@kane81
Copy link
Author

kane81 commented Sep 10, 2024

Well at least you can see the code fix I applied without changing the component :)

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

2 participants