Select with custom items
Rendering Select with a custom styled value and SelectItem
's children.
Account
Harry Poe
harry.poe@example.com
Jane Doe
jane.doe@example.com
John Doe
john.doe@example.com
Sonia Poe
sonia.poe@example.com
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
import * as Ariakit from "@ariakit/react";import startCase from "lodash-es/startCase.js";import { useState } from "react";import "./style.css";function renderValue(email: string) {const [username = ""] = email.split("@");const name = startCase(username.replace(/[._]/g, " "));const image = `https://i.pravatar.cc/120?u=${email}`;return (<><img key={image} src={image} alt="" aria-hidden className="photo" /><div className="value"><div className="name">{name}</div><div className="email">{email}</div></div></>);}const accounts = ["harry.poe@example.com","jane.doe@example.com","john.doe@example.com","sonia.poe@example.com",];export default function Example() {const [value, setValue] = useState("john.doe@example.com");return (<div className="wrapper">{renderValue(value)}{accounts.map((email) => (key={email}className="select-item">{renderValue(email)}))}</div>);}import * as Ariakit from "@ariakit/react";import startCase from "lodash-es/startCase.js";import { useState } from "react";import "./style.css";function renderValue(email: string) {const [username = ""] = email.split("@");const name = startCase(username.replace(/[._]/g, " "));const image = `https://i.pravatar.cc/120?u=${email}`;return (<><img key={image} src={image} alt="" aria-hidden className="photo" /><div className="value"><div className="name">{name}</div><div className="email">{email}</div></div></>);}const accounts = ["harry.poe@example.com","jane.doe@example.com","john.doe@example.com","sonia.poe@example.com",];export default function Example() {const [value, setValue] = useState("john.doe@example.com");return (<div className="wrapper">{renderValue(value)}{accounts.map((email) => (key={email}className="select-item">{renderValue(email)}))}</div>);}