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.
This commit is contained in:
1 parent
2dfc365dbd
commit
3a264ac2df
9 files changed
+264
-56
No files matched your search
@@ -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<HTMLButtonElement>;
|
||||
menuRef: React.RefObject<HTMLDivElement>;
|
||||
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 && (
|
||||
<div
|
||||
ref={menuRef}
|
||||
className="absolute top-full left-0 right-0 z-50 mt-1"
|
||||
>
|
||||
<SelectDropdown ariaLabel={selectAriaLabel}>
|
||||
{options && Array.isArray(options)
|
||||
? options.map((option) => (
|
||||
{isOpen && menuStyle && typeof document !== "undefined"
|
||||
? createPortal(
|
||||
<div
|
||||
ref={menuRef}
|
||||
className="fixed z-[10050]"
|
||||
style={menuStyle}
|
||||
>
|
||||
<SelectDropdown id={listboxId} ariaLabel={selectAriaLabel}>
|
||||
{optionEntries.map((option, index) => (
|
||||
<SelectOption
|
||||
key={option.value}
|
||||
id={`${listboxId}-option-${index}`}
|
||||
selected={option.value === selectedValue}
|
||||
highlighted={index === highlightedIndex}
|
||||
size="medium"
|
||||
onClick={() => onOptionClick(option.value, option.label)}
|
||||
>
|
||||
{option.label}
|
||||
</SelectOption>
|
||||
))
|
||||
: Children.map(children, (child) => {
|
||||
if (
|
||||
React.isValidElement(child) &&
|
||||
child.type === "option"
|
||||
) {
|
||||
const optionProps = child.props as {
|
||||
value: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
return (
|
||||
<SelectOption
|
||||
key={optionProps.value}
|
||||
selected={optionProps.value === selectedValue}
|
||||
size="medium"
|
||||
onClick={() =>
|
||||
onOptionClick(
|
||||
optionProps.value,
|
||||
String(optionProps.children),
|
||||
)
|
||||
}
|
||||
>
|
||||
{optionProps.children}
|
||||
</SelectOption>
|
||||
);
|
||||
}
|
||||
return child;
|
||||
})}
|
||||
</SelectDropdown>
|
||||
</div>
|
||||
)}
|
||||
))}
|
||||
</SelectDropdown>
|
||||
</div>,
|
||||
document.body,
|
||||
)
|
||||
: null}
|
||||
</div>
|
||||
{textHint && (
|
||||
<div className="flex items-start relative shrink-0 w-full">
|
||||
|
||||
Reference in new issue
Block a user