From 3a264ac2dff6bd6d5d9858c9d0822c0cdd24d562 Mon Sep 17 00:00:00 2001 From: adilallo <39313955+adilallo@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:41:05 -0700 Subject: [PATCH 1/5] 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. --- .../controls/SelectInput/SelectDropdown.tsx | 2 +- .../SelectInput/SelectInput.container.tsx | 153 ++++++++++++++++-- .../controls/SelectInput/SelectInput.view.tsx | 90 ++++++----- .../SelectOption/SelectOption.container.tsx | 9 +- .../SelectOption/SelectOption.types.ts | 4 + .../SelectOption/SelectOption.view.tsx | 4 +- app/components/modals/Share/Share.view.tsx | 2 +- tests/components/SelectInput.test.tsx | 34 ++++ tests/components/modals/Share.test.tsx | 22 +++ 9 files changed, 264 insertions(+), 56 deletions(-) diff --git a/app/components/controls/SelectInput/SelectDropdown.tsx b/app/components/controls/SelectInput/SelectDropdown.tsx index 79237d0..c840771 100644 --- a/app/components/controls/SelectInput/SelectDropdown.tsx +++ b/app/components/controls/SelectInput/SelectDropdown.tsx @@ -16,8 +16,8 @@ const SelectDropdown = forwardRef( rounded-[var(--radius-400)] shadow-lg p-[4px] + w-full min-w-[200px] - max-w-[300px] ${className} ` .trim() diff --git a/app/components/controls/SelectInput/SelectInput.container.tsx b/app/components/controls/SelectInput/SelectInput.container.tsx index b23d0da..c77f47d 100644 --- a/app/components/controls/SelectInput/SelectInput.container.tsx +++ b/app/components/controls/SelectInput/SelectInput.container.tsx @@ -2,6 +2,7 @@ import React, { Children, + type CSSProperties, type ReactElement, type ReactNode, forwardRef, @@ -12,11 +13,13 @@ import React, { memo, useImperativeHandle, useEffect, + useLayoutEffect, + useMemo, } from "react"; import { useClickOutside } from "../../../hooks"; import { useTranslation } from "../../../contexts/MessagesContext"; import { SelectInputView } from "./SelectInput.view"; -import type { SelectInputProps } from "./SelectInput.types"; +import type { SelectInputProps, SelectOptionData } from "./SelectInput.types"; /** * Figma: "Control / SelectInput". Custom-styled select dropdown @@ -70,11 +73,31 @@ const SelectInputContainer = forwardRef( const generatedId = useId(); const selectId = id || `select-input-${generatedId}`; const labelId = `${selectId}-label`; + const listboxId = `${selectId}-listbox`; const [isOpen, setIsOpen] = useState(false); const [selectedValue, setSelectedValue] = useState(value || ""); + const [highlightedIndex, setHighlightedIndex] = useState(0); + const [menuStyle, setMenuStyle] = useState(null); const selectRef = useRef(null); const menuRef = useRef(null); + const optionItems = useMemo((): SelectOptionData[] => { + if (options && Array.isArray(options)) return options; + return Children.toArray(children).flatMap((child) => { + if (!React.isValidElement(child) || child.type !== "option") return []; + const optionProps = child.props as { + value: string; + children: ReactNode; + }; + return [ + { + value: optionProps.value, + label: String(optionProps.children), + }, + ]; + }); + }, [options, children]); + // Internal state management: track if focused and how (mouse vs keyboard) const [isFocused, setIsFocused] = useState(false); const [focusMethod, setFocusMethod] = useState<"mouse" | "keyboard" | null>( @@ -99,14 +122,69 @@ const SelectInputContainer = forwardRef( () => selectRef.current as HTMLButtonElement | null, ); + const closeMenu = useCallback(() => { + setIsOpen(false); + setMenuStyle(null); + }, []); + // Handle click outside to close menu - useClickOutside([menuRef, selectRef], () => setIsOpen(false), isOpen); + useClickOutside([menuRef, selectRef], closeMenu, isOpen); + + const indexForValue = useCallback( + (current: string) => { + const index = optionItems.findIndex((option) => option.value === current); + return index >= 0 ? index : 0; + }, + [optionItems], + ); + + const openMenu = useCallback(() => { + const trigger = selectRef.current?.getBoundingClientRect(); + setMenuStyle({ + top: (trigger?.bottom ?? 0) + 4, + left: trigger?.left ?? 0, + width: Math.max(trigger?.width ?? 0, 200), + }); + setHighlightedIndex(indexForValue(selectedValue)); + setIsOpen(true); + }, [indexForValue, selectedValue]); + + useLayoutEffect(() => { + if (!isOpen) { + setMenuStyle(null); + return; + } + const update = () => { + const trigger = selectRef.current; + if (!trigger) return; + const rect = trigger.getBoundingClientRect(); + const menuHeight = menuRef.current?.offsetHeight ?? optionItems.length * 44 + 8; + const gap = 4; + const openUp = + rect.bottom + gap + menuHeight > window.innerHeight && + rect.top > menuHeight + gap; + setMenuStyle({ + top: openUp + ? Math.max(8, rect.top - menuHeight - gap) + : rect.bottom + gap, + left: rect.left, + width: Math.max(rect.width, 200), + }); + }; + update(); + window.addEventListener("resize", update); + window.addEventListener("scroll", update, true); + return () => { + window.removeEventListener("resize", update); + window.removeEventListener("scroll", update, true); + }; + }, [isOpen, optionItems.length, highlightedIndex]); // Handle option selection const handleOptionSelect = useCallback( (optionValue: string, optionText: string) => { setSelectedValue(optionValue); - setIsOpen(false); + closeMenu(); if (onChange) { onChange({ target: { value: optionValue, text: optionText } }); } @@ -114,7 +192,7 @@ const SelectInputContainer = forwardRef( selectRef.current.focus(); } }, - [onChange], + [closeMenu, onChange], ); // Handle mouse down to detect mouse clicks @@ -126,24 +204,74 @@ const SelectInputContainer = forwardRef( // Handle select button click const handleSelectClick = useCallback(() => { - if (!disabled) { - setIsOpen(!isOpen); + if (disabled) return; + if (isOpen) { + closeMenu(); + return; } - }, [disabled, isOpen]); + openMenu(); + }, [closeMenu, disabled, isOpen, openMenu]); // Handle keyboard navigation const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (disabled) return; + if (e.key === "ArrowDown") { + e.preventDefault(); + if (!isOpen) { + openMenu(); + return; + } + setHighlightedIndex((index) => + Math.min(index + 1, Math.max(optionItems.length - 1, 0)), + ); + return; + } + if (e.key === "ArrowUp") { + e.preventDefault(); + if (!isOpen) { + openMenu(); + return; + } + setHighlightedIndex((index) => Math.max(index - 1, 0)); + return; + } + if (e.key === "Home" && isOpen) { + e.preventDefault(); + setHighlightedIndex(0); + return; + } + if (e.key === "End" && isOpen) { + e.preventDefault(); + setHighlightedIndex(Math.max(optionItems.length - 1, 0)); + return; + } if (e.key === "Enter" || e.key === " ") { e.preventDefault(); - setIsOpen(!isOpen); - } else if (e.key === "Escape") { - setIsOpen(false); + if (!isOpen) { + openMenu(); + return; + } + const option = optionItems[highlightedIndex]; + if (option) { + handleOptionSelect(option.value, option.label); + } + return; + } + if (e.key === "Escape") { + closeMenu(); } }, - [disabled, isOpen], + [ + closeMenu, + disabled, + handleOptionSelect, + highlightedIndex, + isOpen, + openMenu, + optionItems, + ], ); // Handle focus to detect mouse vs keyboard @@ -237,6 +365,9 @@ const SelectInputContainer = forwardRef( onOptionClick={handleOptionSelect} selectRef={selectRef} menuRef={menuRef} + listboxId={listboxId} + highlightedIndex={highlightedIndex} + menuStyle={menuStyle} ariaLabelledby={shouldShowLabel ? labelId : undefined} ariaInvalid={error} asterisk={asterisk} diff --git a/app/components/controls/SelectInput/SelectInput.view.tsx b/app/components/controls/SelectInput/SelectInput.view.tsx index 0b40e89..8141705 100644 --- a/app/components/controls/SelectInput/SelectInput.view.tsx +++ b/app/components/controls/SelectInput/SelectInput.view.tsx @@ -1,4 +1,5 @@ -import React, { Children, type ReactNode } from "react"; +import React, { Children, type CSSProperties, type ReactNode } from "react"; +import { createPortal } from "react-dom"; import { getAssetPath, ASSETS } from "../../../../lib/assetUtils"; import SelectDropdown from "./SelectDropdown"; import SelectOption from "../SelectOption"; @@ -30,6 +31,9 @@ export interface SelectInputViewProps { // Refs selectRef: React.RefObject; menuRef: React.RefObject; + listboxId: string; + highlightedIndex: number; + menuStyle: CSSProperties | null; // Additional props ariaLabelledby?: string; ariaInvalid?: boolean; @@ -66,6 +70,9 @@ export function SelectInputView({ onOptionClick, selectRef, menuRef, + listboxId, + highlightedIndex, + menuStyle, ariaLabelledby, ariaInvalid, asterisk = false, @@ -132,6 +139,29 @@ export function SelectInputView({ const buttonClasses = getButtonClasses(); + const optionEntries: SelectOptionData[] = + options && Array.isArray(options) + ? options + : Children.toArray(children).flatMap((child) => { + if (!React.isValidElement(child) || child.type !== "option") { + return []; + } + const optionProps = child.props as { + value: string; + children: ReactNode; + }; + return [ + { + value: optionProps.value, + label: String(optionProps.children), + }, + ]; + }); + + const highlightedValue = optionEntries[highlightedIndex]?.value; + const activeOptionId = + highlightedValue != null ? `${listboxId}-option-${highlightedIndex}` : undefined; + // Text color based on filled state const textColorClass = isFilled ? "text-[var(--color-content-default-primary)]" @@ -183,6 +213,8 @@ export function SelectInputView({ aria-invalid={ariaInvalid} aria-expanded={isOpen} aria-haspopup="listbox" + aria-controls={isOpen ? listboxId : undefined} + aria-activedescendant={isOpen ? activeOptionId : undefined} onClick={onButtonClick} onKeyDown={onButtonKeyDown} onMouseDown={onButtonMouseDown} @@ -219,53 +251,31 @@ export function SelectInputView({ /> )} - {isOpen && ( -
- - {options && Array.isArray(options) - ? options.map((option) => ( + {isOpen && menuStyle && typeof document !== "undefined" + ? createPortal( +
+ + {optionEntries.map((option, index) => ( onOptionClick(option.value, option.label)} > {option.label} - )) - : Children.map(children, (child) => { - if ( - React.isValidElement(child) && - child.type === "option" - ) { - const optionProps = child.props as { - value: string; - children: ReactNode; - }; - return ( - - onOptionClick( - optionProps.value, - String(optionProps.children), - ) - } - > - {optionProps.children} - - ); - } - return child; - })} - -
- )} + ))} +
+
, + document.body, + ) + : null} {textHint && (
diff --git a/app/components/controls/SelectOption/SelectOption.container.tsx b/app/components/controls/SelectOption/SelectOption.container.tsx index 05d0a9b..28526db 100644 --- a/app/components/controls/SelectOption/SelectOption.container.tsx +++ b/app/components/controls/SelectOption/SelectOption.container.tsx @@ -13,8 +13,10 @@ const SelectOptionContainer = forwardRef( { children, selected = false, + highlighted = false, disabled = false, className = "", + id, onClick, size: sizeProp = "medium", ...props @@ -35,15 +37,17 @@ const SelectOptionContainer = forwardRef( } }; + const active = selected || highlighted; const itemClasses = ` flex items-center justify-between - px-[8px] py-[4px] + 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 ${ - selected + active ? "bg-[var(--color-surface-default-secondary)] rounded-[var(--radius-300)]" : "" } @@ -85,6 +89,7 @@ const SelectOptionContainer = forwardRef( disabled={disabled} className={className} itemClasses={itemClasses} + optionId={id} handleClick={handleClick} handleKeyDown={handleKeyDown} {...props} diff --git a/app/components/controls/SelectOption/SelectOption.types.ts b/app/components/controls/SelectOption/SelectOption.types.ts index 4a86be4..41eb19d 100644 --- a/app/components/controls/SelectOption/SelectOption.types.ts +++ b/app/components/controls/SelectOption/SelectOption.types.ts @@ -3,8 +3,11 @@ export type SelectOptionSizeValue = "small" | "medium" | "large"; export interface SelectOptionProps { children?: React.ReactNode; selected?: boolean; + /** Keyboard highlight in a listbox; distinct from the selected value. */ + highlighted?: boolean; disabled?: boolean; className?: string; + id?: string; onClick?: ( _e: React.MouseEvent | React.KeyboardEvent, ) => void; @@ -20,6 +23,7 @@ export interface SelectOptionViewProps { disabled: boolean; className: string; itemClasses: string; + optionId?: string; handleClick: (_e: React.MouseEvent) => void; handleKeyDown: (_e: React.KeyboardEvent) => void; } diff --git a/app/components/controls/SelectOption/SelectOption.view.tsx b/app/components/controls/SelectOption/SelectOption.view.tsx index 04c1a4a..d3e3be8 100644 --- a/app/components/controls/SelectOption/SelectOption.view.tsx +++ b/app/components/controls/SelectOption/SelectOption.view.tsx @@ -11,6 +11,7 @@ export const SelectOptionView = forwardRef< selected, disabled, itemClasses, + optionId, handleClick, handleKeyDown, ...props @@ -20,9 +21,10 @@ export const SelectOptionView = forwardRef< return (
-
+

{copy.whoCanRead}

diff --git a/tests/components/SelectInput.test.tsx b/tests/components/SelectInput.test.tsx index d2f63e8..4343e72 100644 --- a/tests/components/SelectInput.test.tsx +++ b/tests/components/SelectInput.test.tsx @@ -1,6 +1,10 @@ +import "@testing-library/jest-dom/vitest"; import React from "react"; +import { describe, expect, it, vi } from "vitest"; +import userEvent from "@testing-library/user-event"; import SelectInput from "../../app/components/controls/SelectInput"; import { componentTestSuite } from "../utils/componentTestSuite"; +import { renderWithProviders, screen } from "../utils/test-utils"; type SelectInputProps = React.ComponentProps; @@ -31,3 +35,33 @@ componentTestSuite({ errorProps: { error: true }, }, }); + +describe("SelectInput listbox keyboard", () => { + it("moves between options with arrows and picks with Enter", async () => { + const onChange = vi.fn(); + const user = userEvent.setup(); + renderWithProviders( + , + ); + + const trigger = screen.getByRole("button", { name: /Who can read/i }); + trigger.focus(); + await user.keyboard("{ArrowDown}"); + expect(await screen.findByRole("option", { name: "Option 1" })).toBeVisible(); + expect(screen.getByRole("option", { name: "Option 2" })).toBeVisible(); + await user.keyboard("{ArrowDown}{Enter}"); + expect(onChange).toHaveBeenCalledWith({ + target: { value: "option2", text: "Option 2" }, + }); + expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); + }); +}); diff --git a/tests/components/modals/Share.test.tsx b/tests/components/modals/Share.test.tsx index 1938294..8375348 100644 --- a/tests/components/modals/Share.test.tsx +++ b/tests/components/modals/Share.test.tsx @@ -201,6 +201,28 @@ describe("Share modal", () => { ).toBeInTheDocument(); }); + it("shows both access options and picks one with arrow keys", async () => { + const user = userEvent.setup(); + openShare(); + const trigger = screen.getByRole("button", { + name: /Only people you invite/i, + }); + trigger.focus(); + await user.keyboard("{ArrowDown}"); + const inviteOnly = await screen.findByRole("option", { + name: "Only people you invite", + }); + const anyone = screen.getByRole("option", { name: "Anyone with the link" }); + expect(inviteOnly).toBeVisible(); + expect(anyone).toBeVisible(); + await user.keyboard("{ArrowDown}{Enter}"); + expect( + screen.getByText( + "Anyone with the link can read it without logging in and pass it on. Check with your community first.", + ), + ).toBeInTheDocument(); + }); + it("calls onClose when Done is clicked", async () => { const user = userEvent.setup(); const onClose = vi.fn(); From 0fe2624002d84c2642cbf980ec052fb28d8f7262 Mon Sep 17 00:00:00 2001 From: adilallo <39313955+adilallo@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:42:49 -0700 Subject: [PATCH 2/5] Show Share initials, a readable link, and a copy confirmation. Filled avatars used white ink on yellow, the link field was a dimmed disabled input, and Copy failed silently when the clipboard API was denied. --- app/(marketing)/r/[shareSlug]/page.tsx | 5 +-- app/components/asset/Avatar/Avatar.tsx | 2 +- .../TextInput/TextInput.container.tsx | 12 ++++++ .../controls/TextInput/TextInput.types.ts | 2 + .../controls/TextInput/TextInput.view.tsx | 2 + .../modals/Share/Share.container.tsx | 18 +++++++- app/components/modals/Share/Share.view.tsx | 13 +++--- tests/components/Avatar.test.tsx | 9 ++++ tests/components/TextInput.test.tsx | 15 +++++++ tests/components/modals/Share.test.tsx | 27 ++++++++++-- tests/pages/shared-rule.test.ts | 41 +++++++++++++++++++ 11 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 tests/pages/shared-rule.test.ts diff --git a/app/(marketing)/r/[shareSlug]/page.tsx b/app/(marketing)/r/[shareSlug]/page.tsx index 74dc1a0..cebb02d 100644 --- a/app/(marketing)/r/[shareSlug]/page.tsx +++ b/app/(marketing)/r/[shareSlug]/page.tsx @@ -30,10 +30,7 @@ export async function generateMetadata({ const { shareSlug } = await params; const resolved = await loadSharedRule(shareSlug); if (!resolved) { - return { - title: messages.pages.ruleDetail.notFoundTitle, - description: "The requested CommunityRule could not be found.", - }; + notFound(); } const { rule } = resolved; const description = diff --git a/app/components/asset/Avatar/Avatar.tsx b/app/components/asset/Avatar/Avatar.tsx index a37b590..d01153c 100644 --- a/app/components/asset/Avatar/Avatar.tsx +++ b/app/components/asset/Avatar/Avatar.tsx @@ -97,7 +97,7 @@ const Avatar = memo( const fallbackChrome = variant === "outlined" ? "border-[1.5px] border-solid border-[var(--color-content-default-brand-primary)] bg-transparent text-[var(--color-content-default-brand-primary)]" - : "bg-[var(--color-surface-invert-brand-primary)] text-[var(--color-content-default-primary)]"; + : "bg-[var(--color-surface-invert-brand-primary)] text-[var(--color-content-invert-primary)]"; // White 30% ring on small photos: no DS token (opacity scale is black-alpha). const smallImageBorder = size === "small" && showImage && loaded diff --git a/app/components/controls/TextInput/TextInput.container.tsx b/app/components/controls/TextInput/TextInput.container.tsx index 5f750a4..1f935b1 100644 --- a/app/components/controls/TextInput/TextInput.container.tsx +++ b/app/components/controls/TextInput/TextInput.container.tsx @@ -16,6 +16,7 @@ const TextInputContainer = forwardRef( state: externalStateProp = "default", inputSize: inputSizeProp = "medium", disabled = false, + readOnly = false, error = false, label, placeholder, @@ -109,6 +110,16 @@ const TextInputContainer = forwardRef( }; } + if (readOnly) { + return { + input: + "bg-[var(--color-surface-default-secondary)] text-[var(--color-content-default-primary)] border border-solid border-[var(--color-border-default-primary)] cursor-default", + label: "text-[var(--color-content-default-secondary)]", + inputWrapper: "relative", + focusRing: "", + }; + } + if (error) { const filledStyles = isFilled ? "font-medium leading-[20px]" @@ -231,6 +242,7 @@ const TextInputContainer = forwardRef( labelId={labelId} state={actualState} disabled={disabled} + readOnly={readOnly} error={error} label={label} placeholder={placeholder} diff --git a/app/components/controls/TextInput/TextInput.types.ts b/app/components/controls/TextInput/TextInput.types.ts index c445828..2ecc8f3 100644 --- a/app/components/controls/TextInput/TextInput.types.ts +++ b/app/components/controls/TextInput/TextInput.types.ts @@ -16,6 +16,7 @@ export interface TextInputProps extends Omit< */ inputSize?: TextInputSizeValue; disabled?: boolean; + readOnly?: boolean; error?: boolean; label?: string; placeholder?: string; @@ -43,6 +44,7 @@ export interface TextInputViewProps { labelId: string; state: "default" | "active" | "hover" | "focus"; disabled: boolean; + readOnly: boolean; error: boolean; label?: string; placeholder?: string; diff --git a/app/components/controls/TextInput/TextInput.view.tsx b/app/components/controls/TextInput/TextInput.view.tsx index 3b3b5a0..07687f1 100644 --- a/app/components/controls/TextInput/TextInput.view.tsx +++ b/app/components/controls/TextInput/TextInput.view.tsx @@ -13,6 +13,7 @@ export const TextInputView = forwardRef( name, type, disabled, + readOnly = false, error = false, className: _className, containerClasses, @@ -90,6 +91,7 @@ export const TextInputView = forwardRef( onKeyDown={onKeyDown} onMouseDown={handleMouseDown} disabled={disabled} + readOnly={readOnly} maxLength={maxLength} autoComplete={autoComplete} inputMode={inputMode} diff --git a/app/components/modals/Share/Share.container.tsx b/app/components/modals/Share/Share.container.tsx index 625add6..fbea707 100644 --- a/app/components/modals/Share/Share.container.tsx +++ b/app/components/modals/Share/Share.container.tsx @@ -245,9 +245,25 @@ const ShareContainer = memo((props) => { const handleCopyLink = useCallback(async () => { if (!settings) return; + const text = settings.shareUrl; try { - await navigator.clipboard.writeText(settings.shareUrl); + await navigator.clipboard.writeText(text); setLinkCopied(true); + return; + } catch { + // Some browsers deny clipboard without a secure context; fall back. + } + try { + const field = document.createElement("textarea"); + field.value = text; + field.setAttribute("readonly", ""); + field.style.position = "fixed"; + field.style.left = "-9999px"; + document.body.appendChild(field); + field.select(); + const copied = document.execCommand("copy"); + field.remove(); + setLinkCopied(copied); } catch { setLinkCopied(false); } diff --git a/app/components/modals/Share/Share.view.tsx b/app/components/modals/Share/Share.view.tsx index d310109..a8b02f4 100644 --- a/app/components/modals/Share/Share.view.tsx +++ b/app/components/modals/Share/Share.view.tsx @@ -170,7 +170,7 @@ export const ShareView = memo(function ShareView({ buttonType="outline" palette="default" size="small" - disabled={inviteBusy || inviteValue.trim().length === 0} + disabled={inviteBusy} onClick={onInvite} > {copy.invite} @@ -252,7 +252,7 @@ export const ShareView = memo(function ShareView({ showHelpIcon={false} label={copy.anyoneWithLink} value={shareUrlDisplay} - disabled + readOnly textHint={copy.linkHint} />
+ + {linkCopied ? ( +
- ) : null} -
+
+ ) : null}
+ , + ); + + const trigger = screen.getByRole("button", { name: /Who can read/i }); + await user.click(trigger); + expect(await screen.findByRole("listbox")).toBeVisible(); + await user.click(screen.getByRole("button", { name: "Next" })); + expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); + }); + + it("Escape closes the listbox and does not reach document listeners", async () => { + const user = userEvent.setup(); + const onDocumentKeyDown = vi.fn(); + document.addEventListener("keydown", onDocumentKeyDown); + renderWithProviders( + , + ); + + const trigger = screen.getByRole("button", { name: /Who can read/i }); + trigger.focus(); + await user.keyboard("{ArrowDown}"); + expect(await screen.findByRole("listbox")).toBeVisible(); + onDocumentKeyDown.mockClear(); + await user.keyboard("{Escape}"); + expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); + expect(onDocumentKeyDown).not.toHaveBeenCalled(); + document.removeEventListener("keydown", onDocumentKeyDown); + }); + + it("selects an option that is clicked", async () => { + const onChange = vi.fn(); + const user = userEvent.setup(); + renderWithProviders( + , + ); + + await user.click(screen.getByRole("button", { name: /Who can read/i })); + await user.click(await screen.findByRole("option", { name: "Option 2" })); + expect(onChange).toHaveBeenCalledWith({ + target: { value: "option2", text: "Option 2" }, + }); + expect(screen.queryByRole("listbox")).not.toBeInTheDocument(); + }); }); diff --git a/tests/pages/shared-rule.test.ts b/tests/pages/shared-rule.test.ts index d5d2af3..2a7c1aa 100644 --- a/tests/pages/shared-rule.test.ts +++ b/tests/pages/shared-rule.test.ts @@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; const getReadablePublishedRuleMock = vi.fn(); const getSessionUserMock = vi.fn(); +const rateLimitKeyMock = vi.fn(); const notFoundMock = vi.fn(() => { throw new Error("NEXT_NOT_FOUND"); }); @@ -16,10 +17,11 @@ vi.mock("next/headers", () => ({ })); vi.mock("../../lib/server/rateLimit", () => ({ - rateLimitKey: () => ({ ok: true }), + rateLimitKey: (...args: unknown[]) => rateLimitKeyMock(...args), })); vi.mock("../../lib/server/publishedRules", () => ({ + SHARE_LOOKUP_MISS_INTERVAL_MS: 1_000, getReadablePublishedRule: (...args: unknown[]) => getReadablePublishedRuleMock(...args), })); @@ -34,6 +36,8 @@ describe("shared Rule page", () => { beforeEach(() => { getReadablePublishedRuleMock.mockReset(); getSessionUserMock.mockReset(); + rateLimitKeyMock.mockReset(); + rateLimitKeyMock.mockReturnValue({ ok: true }); notFoundMock.mockClear(); getSessionUserMock.mockResolvedValue(null); }); @@ -47,4 +51,18 @@ describe("shared Rule page", () => { ).rejects.toThrow("NEXT_NOT_FOUND"); expect(notFoundMock).toHaveBeenCalled(); }); + + it("does not look up a malformed slug when the miss limit refuses", async () => { + rateLimitKeyMock.mockReturnValue({ ok: false, retryAfterMs: 1_000 }); + await expect( + generateMetadata({ + params: Promise.resolve({ shareSlug: "not-a-slug" }), + }), + ).rejects.toThrow("NEXT_NOT_FOUND"); + expect(rateLimitKeyMock).toHaveBeenCalledWith( + "share-lookup-miss:203.0.113.8", + 1_000, + ); + expect(getReadablePublishedRuleMock).not.toHaveBeenCalled(); + }); }); diff --git a/tests/unit/publishedRules.test.ts b/tests/unit/publishedRules.test.ts index 136bd58..9743fcf 100644 --- a/tests/unit/publishedRules.test.ts +++ b/tests/unit/publishedRules.test.ts @@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; const isDatabaseConfiguredMock = vi.fn(); const findUniqueMock = vi.fn(); const rateLimitKeyMock = vi.fn(); +const rateLimitCoolingDownMock = vi.fn(); const findManyMock = vi.fn(); const stakeholderFindManyMock = vi.fn(); const browserHoldsClaimForHashMock = vi.fn(); @@ -15,6 +16,8 @@ vi.mock("../../lib/server/env", () => ({ vi.mock("../../lib/server/rateLimit", () => ({ rateLimitKey: (...args: unknown[]) => rateLimitKeyMock(...args), + rateLimitCoolingDown: (...args: unknown[]) => + rateLimitCoolingDownMock(...args), })); vi.mock("../../lib/server/db", () => ({ @@ -77,10 +80,12 @@ beforeEach(() => { isRuleAdminEmailMock.mockReset(); logAdminRuleReadMock.mockReset(); rateLimitKeyMock.mockReset(); + rateLimitCoolingDownMock.mockReset(); browserHoldsClaimForHashMock.mockResolvedValue(false); isRuleAdminEmailMock.mockReturnValue(false); logAdminRuleReadMock.mockResolvedValue(undefined); rateLimitKeyMock.mockReturnValue({ ok: true }); + rateLimitCoolingDownMock.mockReturnValue(false); }); describe("getReadablePublishedRule", () => { @@ -245,6 +250,38 @@ describe("getReadablePublishedRule", () => { 1_000, ); }); + + it("does not query when a share-slug miss is still cooling down", async () => { + isDatabaseConfiguredMock.mockReturnValue(true); + rateLimitCoolingDownMock.mockReturnValue(true); + expect( + await getReadablePublishedRule({ + idOrSlug: "k7f2-9qxm", + user: null, + viaShareSlug: true, + requestPath: "/r/k7f2-9qxm", + failedLookupKey: "203.0.113.8", + }), + ).toBeNull(); + expect(findUniqueMock).not.toHaveBeenCalled(); + expect(rateLimitKeyMock).not.toHaveBeenCalled(); + }); + + it("returns null when the miss limit refuses after a lookup", async () => { + isDatabaseConfiguredMock.mockReturnValue(true); + findUniqueMock.mockResolvedValueOnce(null); + rateLimitKeyMock.mockReturnValue({ ok: false, retryAfterMs: 400 }); + expect( + await getReadablePublishedRule({ + idOrSlug: "k7f2-9qxm", + user: null, + viaShareSlug: true, + requestPath: "/r/k7f2-9qxm", + failedLookupKey: "203.0.113.8", + }), + ).toBeNull(); + expect(findUniqueMock).toHaveBeenCalledTimes(1); + }); }); describe("listListedPublishedRules", () => { From 27f06dd7b0db645fca425379e1a72dfaa1a6ec88 Mon Sep 17 00:00:00 2001 From: adilallo <39313955+adilallo@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:32:51 -0700 Subject: [PATCH 5/5] Scroll the Share people list on a short frame instead of squashing it. Overflow-hidden let flex shrink the avatar rows, and the pane used the browser scrollbar instead of the design-system one. --- app/components/modals/Share/Share.view.tsx | 8 +++++--- tests/components/modals/Share.test.tsx | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/components/modals/Share/Share.view.tsx b/app/components/modals/Share/Share.view.tsx index a8b02f4..dcb9363 100644 --- a/app/components/modals/Share/Share.view.tsx +++ b/app/components/modals/Share/Share.view.tsx @@ -41,7 +41,7 @@ function PersonRow(props: { roleLabel: string; }) { return ( -
+
-
+
+
) : null} -
+

{copy.peopleWithAccess}

@@ -303,6 +304,7 @@ export const ShareView = memo(function ShareView({
) : null} +
{linkCopied ? ( diff --git a/tests/components/modals/Share.test.tsx b/tests/components/modals/Share.test.tsx index 929bc1b..8302253 100644 --- a/tests/components/modals/Share.test.tsx +++ b/tests/components/modals/Share.test.tsx @@ -86,6 +86,9 @@ describe("Share modal", () => { ).toBeInTheDocument(); expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument(); expect(screen.getByText("You")).toBeInTheDocument(); + const people = screen.getByText("People with access").parentElement; + expect(people).not.toHaveClass("overflow-hidden"); + expect(people?.parentElement?.parentElement).toHaveClass("scrollbar-design"); expect(screen.getByText("N")).toBeInTheDocument(); expect(screen.getByText("R")).toBeInTheDocument(); expect(screen.getByRole("button", { name: "Invite" })).toBeEnabled();