Select Grid
Using Select with SelectPopover
rendered with the grid
role to create a bidimensional list of selectable items.
Position
Top Left
Top Center
Top Right
Center Left
Center
Center Right
Bottom Left
Bottom Center
Bottom Right
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
import * as Ariakit from "@ariakit/react";import { useState } from "react";import Square from "./square.tsx";import "./style.css";export default function Example() {const [value, setValue] = useState("Center");const renderItem = (value: string) => (role="gridcell"className="select-item"// When the mouse leaves the item, we don't want to unset the active// item.if (event.type === "mouseleave") return false;// By default, hovering over an item doesn't focus it, nor does it set// the value. So we need to manually "move" to the item so it gets// focused and the value is set.select.move(event.currentTarget.id);return true;}}>);return (<div className="wrapper"><Square value={value} />{value}{renderItem("Top Left")}{renderItem("Top Center")}{renderItem("Top Right")}{renderItem("Center Left")}{renderItem("Center")}{renderItem("Center Right")}{renderItem("Bottom Left")}{renderItem("Bottom Center")}{renderItem("Bottom Right")}</div>);}import * as Ariakit from "@ariakit/react";import { useState } from "react";import Square from "./square.tsx";import "./style.css";export default function Example() {const [value, setValue] = useState("Center");const renderItem = (value: string) => (role="gridcell"className="select-item"// When the mouse leaves the item, we don't want to unset the active// item.if (event.type === "mouseleave") return false;// By default, hovering over an item doesn't focus it, nor does it set// the value. So we need to manually "move" to the item so it gets// focused and the value is set.select.move(event.currentTarget.id);return true;}}>);return (<div className="wrapper"><Square value={value} />{value}{renderItem("Top Left")}{renderItem("Top Center")}{renderItem("Top Right")}{renderItem("Center Left")}{renderItem("Center")}{renderItem("Center Right")}{renderItem("Bottom Left")}{renderItem("Bottom Center")}{renderItem("Bottom Right")}</div>);}