Consolidate roving tab index controls in the space panel buttons with dnd
parent
6a40dfea40
commit
898de13ca7
|
@ -195,12 +195,10 @@ const InnerSpacePanel = React.memo<IInnerSpacePanelProps>(({ children, isPanelCo
|
||||||
{ (provided, snapshot) => (
|
{ (provided, snapshot) => (
|
||||||
<SpaceItem
|
<SpaceItem
|
||||||
{...provided.draggableProps}
|
{...provided.draggableProps}
|
||||||
{...provided.dragHandleProps}
|
dragHandleProps={provided.dragHandleProps}
|
||||||
key={s.roomId}
|
key={s.roomId}
|
||||||
innerRef={provided.innerRef}
|
innerRef={provided.innerRef}
|
||||||
className={snapshot.isDragging
|
className={snapshot.isDragging ? "mx_SpaceItem_dragging" : undefined}
|
||||||
? "mx_SpaceItem_dragging"
|
|
||||||
: undefined}
|
|
||||||
space={s}
|
space={s}
|
||||||
activeSpaces={activeSpaces}
|
activeSpaces={activeSpaces}
|
||||||
isPanelCollapsed={isPanelCollapsed}
|
isPanelCollapsed={isPanelCollapsed}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import RoomAvatar from "../avatars/RoomAvatar";
|
||||||
import SpaceStore from "../../../stores/SpaceStore";
|
import SpaceStore from "../../../stores/SpaceStore";
|
||||||
import SpaceTreeLevelLayoutStore from "../../../stores/SpaceTreeLevelLayoutStore";
|
import SpaceTreeLevelLayoutStore from "../../../stores/SpaceTreeLevelLayoutStore";
|
||||||
import NotificationBadge from "../rooms/NotificationBadge";
|
import NotificationBadge from "../rooms/NotificationBadge";
|
||||||
import { RovingAccessibleTooltipButton } from "../../../accessibility/roving/RovingAccessibleTooltipButton";
|
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import { ContextMenuTooltipButton } from "../../../accessibility/context_menu/ContextMenuTooltipButton";
|
import { ContextMenuTooltipButton } from "../../../accessibility/context_menu/ContextMenuTooltipButton";
|
||||||
import { toRightOf, useContextMenu } from "../../structures/ContextMenu";
|
import { toRightOf, useContextMenu } from "../../structures/ContextMenu";
|
||||||
|
@ -40,8 +39,11 @@ import { NotificationColor } from "../../../stores/notifications/NotificationCol
|
||||||
import { getKeyBindingsManager, RoomListAction } from "../../../KeyBindingsManager";
|
import { getKeyBindingsManager, RoomListAction } from "../../../KeyBindingsManager";
|
||||||
import { NotificationState } from "../../../stores/notifications/NotificationState";
|
import { NotificationState } from "../../../stores/notifications/NotificationState";
|
||||||
import SpaceContextMenu from "../context_menus/SpaceContextMenu";
|
import SpaceContextMenu from "../context_menus/SpaceContextMenu";
|
||||||
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
||||||
|
import { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
|
||||||
|
import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
|
||||||
|
|
||||||
interface IButtonProps extends Omit<ComponentProps<typeof RovingAccessibleTooltipButton>, "title"> {
|
interface IButtonProps extends Omit<ComponentProps<typeof AccessibleTooltipButton>, "title"> {
|
||||||
space?: Room;
|
space?: Room;
|
||||||
className?: string;
|
className?: string;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
|
@ -68,7 +70,9 @@ export const SpaceButton: React.FC<IButtonProps> = ({
|
||||||
ContextMenuComponent,
|
ContextMenuComponent,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu<HTMLElement>();
|
const [menuDisplayed, ref, openMenu, closeMenu] = useContextMenu<HTMLElement>();
|
||||||
|
const [onFocus, isActive, handle] = useRovingTabIndex(ref);
|
||||||
|
const tabIndex = isActive ? 0 : -1;
|
||||||
|
|
||||||
let avatar = <div className="mx_SpaceButton_avatarPlaceholder"><div className="mx_SpaceButton_icon" /></div>;
|
let avatar = <div className="mx_SpaceButton_avatarPlaceholder"><div className="mx_SpaceButton_icon" /></div>;
|
||||||
if (space) {
|
if (space) {
|
||||||
|
@ -88,6 +92,7 @@ export const SpaceButton: React.FC<IButtonProps> = ({
|
||||||
forceCount={false}
|
forceCount={false}
|
||||||
notification={notificationState}
|
notification={notificationState}
|
||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
|
tabIndex={tabIndex}
|
||||||
/>
|
/>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +107,7 @@ export const SpaceButton: React.FC<IButtonProps> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RovingAccessibleTooltipButton
|
<AccessibleTooltipButton
|
||||||
{...props}
|
{...props}
|
||||||
className={classNames("mx_SpaceButton", className, {
|
className={classNames("mx_SpaceButton", className, {
|
||||||
mx_SpaceButton_active: selected,
|
mx_SpaceButton_active: selected,
|
||||||
|
@ -114,6 +119,8 @@ export const SpaceButton: React.FC<IButtonProps> = ({
|
||||||
onContextMenu={openMenu}
|
onContextMenu={openMenu}
|
||||||
forceHide={!isNarrow || menuDisplayed}
|
forceHide={!isNarrow || menuDisplayed}
|
||||||
inputRef={handle}
|
inputRef={handle}
|
||||||
|
tabIndex={tabIndex}
|
||||||
|
onFocus={onFocus}
|
||||||
>
|
>
|
||||||
{ children }
|
{ children }
|
||||||
<div className="mx_SpaceButton_selectionWrapper">
|
<div className="mx_SpaceButton_selectionWrapper">
|
||||||
|
@ -130,7 +137,7 @@ export const SpaceButton: React.FC<IButtonProps> = ({
|
||||||
|
|
||||||
{ contextMenu }
|
{ contextMenu }
|
||||||
</div>
|
</div>
|
||||||
</RovingAccessibleTooltipButton>
|
</AccessibleTooltipButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,6 +149,7 @@ interface IItemProps extends InputHTMLAttributes<HTMLLIElement> {
|
||||||
onExpand?: Function;
|
onExpand?: Function;
|
||||||
parents?: Set<string>;
|
parents?: Set<string>;
|
||||||
innerRef?: LegacyRef<HTMLLIElement>;
|
innerRef?: LegacyRef<HTMLLIElement>;
|
||||||
|
dragHandleProps?: DraggableProvidedDragHandleProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IItemState {
|
interface IItemState {
|
||||||
|
@ -290,6 +298,9 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
||||||
aria-label={collapsed ? _t("Expand") : _t("Collapse")}
|
aria-label={collapsed ? _t("Expand") : _t("Collapse")}
|
||||||
/> : null;
|
/> : null;
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const { tabIndex, ...dragHandleProps } = this.props.dragHandleProps || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
{...otherProps}
|
{...otherProps}
|
||||||
|
@ -299,6 +310,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
||||||
role="treeitem"
|
role="treeitem"
|
||||||
>
|
>
|
||||||
<SpaceButton
|
<SpaceButton
|
||||||
|
{...dragHandleProps}
|
||||||
space={space}
|
space={space}
|
||||||
className={isInvite ? "mx_SpaceButton_invite" : undefined}
|
className={isInvite ? "mx_SpaceButton_invite" : undefined}
|
||||||
selected={activeSpaces.includes(space)}
|
selected={activeSpaces.includes(space)}
|
||||||
|
|
Loading…
Reference in New Issue