Files
community-rule/app/components/controls/SelectOption/SelectOption.container.tsx
T
adilallo 3a264ac2df Open the Share access menu above the dialog so both options can be picked.
The listbox was clipped inside the sheet, sat at 24px, and ignored arrow keys, so Anyone with the link could not be chosen by mouse or touch.
2026-11-21 11:41:05 -07:00

106 lines
2.5 KiB
TypeScript

"use client";
import { forwardRef, memo, useCallback } from "react";
import { SelectOptionView } from "./SelectOption.view";
import type { SelectOptionProps } from "./SelectOption.types";
/**
* Figma: "Control / SelectOption". Single option row rendered
* inside `SelectInput`'s dropdown menu.
*/
const SelectOptionContainer = forwardRef<HTMLDivElement, SelectOptionProps>(
(
{
children,
selected = false,
highlighted = false,
disabled = false,
className = "",
id,
onClick,
size: sizeProp = "medium",
...props
},
ref,
) => {
const size = sizeProp;
const getTextSize = (): string => {
switch (size) {
case "small":
return "text-xx-small-paragraph";
case "medium":
return "text-small-paragraph";
case "large":
return "text-medium-paragraph";
default:
return "text-small-paragraph";
}
};
const active = selected || highlighted;
const itemClasses = `
flex items-center justify-between
min-h-11 px-[8px] py-2
md:min-h-0 md:py-[4px]
text-[var(--color-content-default-brand-primary)]
${getTextSize()}
cursor-pointer
transition-colors duration-150
${
active
? "bg-[var(--color-surface-default-secondary)] rounded-[var(--radius-300)]"
: ""
}
${
disabled
? "opacity-50 cursor-not-allowed"
: "hover:!bg-[var(--color-surface-default-secondary)] hover:!rounded-[var(--radius-300)]"
}
${className}
`
.trim()
.replace(/\s+/g, " ");
const handleClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (!disabled && onClick) {
onClick(e);
}
},
[disabled, onClick],
);
const handleKeyDown = useCallback(
(e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
if (!disabled && onClick) {
onClick(e);
}
}
},
[disabled, onClick],
);
return (
<SelectOptionView
ref={ref}
selected={selected}
disabled={disabled}
className={className}
itemClasses={itemClasses}
optionId={id}
handleClick={handleClick}
handleKeyDown={handleKeyDown}
{...props}
>
{children}
</SelectOptionView>
);
},
);
SelectOptionContainer.displayName = "SelectOption";
export default memo(SelectOptionContainer);