sdxc

[ @sdxc/u/general ]

user-select

Applies user-select.

import { userSelect } from "@sdxc/u/general";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.userSelect()css({ userSelect: "none" })
u.userSelect("text")css({ userSelect: "text" })

Examples

Basic example

Use userSelect() to keep text from being selected by an incidental click and drag. Try selecting both paragraphs:

userSelect()

The quick brown fox jumps over the lazy dog.

userSelect("auto")

The quick brown fox jumps over the lazy dog.

<div mix={[maxIs(96), ...]}>
	<div>
		<p mix={[...]}>userSelect()</p>
		<p mix={[userSelect()]}>The quick brown fox jumps over the lazy dog.</p>
	</div>
	<div>
		<p mix={[...]}>userSelect("auto")</p>
		<p mix={[userSelect("auto")]}>The quick brown fox jumps over the lazy dog.</p>
	</div>
</div>

Selecting all at once

Use userSelect("all") to select an element's whole text with one click. Click the command:

bun add @sdxc/u
<code mix={[userSelect("all"), font("mono"), ...]}>bun add @sdxc/u</code>

Allowing selection inside

Use userSelect("text") to make part of an unselectable area selectable again. Try selecting the name, then the email:

Ada Lovelace

ada@example.com

<div mix={[userSelect(), ...]}>
	<p mix={[weight("semibold")]}>Ada Lovelace</p>
	<p mix={[userSelect("text"), fg("brand")]}>ada@example.com</p>
</div>

Applying on a state

Wrap the call in a state utility to scope it to one selector.

u.hover(u.userSelect())

Responsive design

Wrap the call in a container query to scope it to one width.

u.at("md", u.userSelect())

Signature

u.userSelect(value?: UserSelectValue)

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.