Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Katerina: beginnings of drag/drop accessibility enhancements #6626

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/react-core/src/components/DragDrop/DragButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import GripVerticalIcon from '@patternfly/react-icons/dist/esm/icons/grip-vertical-icon';
import { Button, ButtonVariant } from '../Button';
import { DraggableContext } from './Draggable';

interface DragButtonProps {
/** Accessible label for the button */
'aria-label'?: string;
}

export const DragButton: React.FunctionComponent<DragButtonProps> = ({
'aria-label': ariaLabel,
...props
}: DragButtonProps) => {
const { setHasDragButtons, onKeyDown } = React.useContext(DraggableContext);

React.useEffect(() => {
setHasDragButtons(true);
}, []);

return (
<Button variant={ButtonVariant.plain} aria-label={ariaLabel} onKeyDown={onKeyDown} {...props}>
<GripVerticalIcon />
</Button>
);
};
DragButton.displayName = 'DragButton';
17 changes: 12 additions & 5 deletions packages/react-core/src/components/DragDrop/DragDrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ interface DraggableItemPosition {
export const DragDropContext = React.createContext({
onDrag: (_source: DraggableItemPosition) => true as boolean,
onDragMove: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => {},
onDrop: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => false as boolean
onDrop: (_source: DraggableItemPosition, _dest?: DraggableItemPosition) => false as boolean,
isDragging: false,
setIsDragging: (isDragging: boolean) => {}
});

interface DragDropProps {
Expand All @@ -28,8 +30,13 @@ export const DragDrop: React.FunctionComponent<DragDropProps> = ({
children,
onDrag = () => true,
onDragMove = () => {},
onDrop = () => false
}: DragDropProps) => (
<DragDropContext.Provider value={{ onDrag, onDragMove, onDrop }}>{children}</DragDropContext.Provider>
);
onDrop = () => false,

}: DragDropProps) => {
const [isDragging, setIsDragging] = React.useState(false);

return (
<DragDropContext.Provider value={{ onDrag, onDragMove, onDrop, isDragging, setIsDragging }}>{children}</DragDropContext.Provider>
);
};
DragDrop.displayName = 'DragDrop';
Loading