mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 00:38:27 +00:00
[Glitch] Allow disabled dropdown menu items to be focused
Port 841212710b to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -186,13 +186,16 @@ export const DropdownMenu = <Item = MenuItem,>({
|
||||
(e: React.MouseEvent | React.KeyboardEvent) => {
|
||||
const i = Number(e.currentTarget.getAttribute('data-index'));
|
||||
const item = items?.[i];
|
||||
const isItemDisabled = Boolean(
|
||||
item && typeof item === 'object' && 'disabled' in item && item.disabled,
|
||||
);
|
||||
|
||||
onClose();
|
||||
|
||||
if (!item) {
|
||||
if (!item || isItemDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
onClose();
|
||||
|
||||
if (typeof onItemClick === 'function') {
|
||||
e.preventDefault();
|
||||
onItemClick(item, i);
|
||||
@@ -233,7 +236,7 @@ export const DropdownMenu = <Item = MenuItem,>({
|
||||
onClick={handleItemClick}
|
||||
onKeyUp={handleItemKeyUp}
|
||||
data-index={i}
|
||||
disabled={disabled}
|
||||
aria-disabled={disabled}
|
||||
>
|
||||
<DropdownMenuItemContent item={option} />
|
||||
</button>
|
||||
@@ -320,7 +323,7 @@ export const DropdownMenu = <Item = MenuItem,>({
|
||||
);
|
||||
};
|
||||
|
||||
interface DropdownProps<Item = MenuItem> {
|
||||
interface DropdownProps<Item extends object | null = MenuItem> {
|
||||
children?: React.ReactElement;
|
||||
icon?: string;
|
||||
iconComponent?: IconProp;
|
||||
@@ -348,7 +351,7 @@ interface DropdownProps<Item = MenuItem> {
|
||||
const offset = [5, 5] as OffsetValue;
|
||||
const popperConfig = { strategy: 'fixed' } as UsePopperOptions;
|
||||
|
||||
export const Dropdown = <Item = MenuItem,>({
|
||||
export const Dropdown = <Item extends object | null = MenuItem>({
|
||||
children,
|
||||
icon,
|
||||
iconComponent,
|
||||
|
||||
Reference in New Issue
Block a user