-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for DropZone isDisabled prop #5958
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good, just a few comments.
if (isDisabled) { | ||
return { | ||
dropProps: {}, | ||
dropButtonProps: {disabled: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want this instead:
dropButtonProps: {disabled: true}, | |
dropButtonProps: {isDisabled: true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By setting disabled
here, I made sure the DropZone can't be focused with the tab key when it's disabled. Other components like NumberField, Switch, and Button don't get tab focus when they're disabled. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the useButton
in DropZone based on dropButtonProps
might be a viable approach. I'll give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it in the following commit:
Fix dropButtonProps using useButton hooks
@@ -56,8 +59,7 @@ export interface DropResult { | |||
/** Whether the drop target is currently focused or hovered. */ | |||
isDropTarget: boolean, | |||
/** Props for the explicit drop button affordance, if any. */ | |||
dropButtonProps?: AriaButtonProps | |||
|
|||
dropButtonProps?: ButtonHTMLAttributes<HTMLButtonElement> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this type should be changing.
let isFocusedRef = useRef(false); | ||
let {focusProps} = useFocus({ | ||
isDisabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question for the team: Should focus events be disabled here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should always be enabled, otherwise you could end up in a scenario where the isDisabled
prop is toggled, but focus occurred while disabled, then the isFocusedRef wouldn't be correct.
We're not sending any focus callbacks into useClipboard
, so it won't be a problem of calling onFocus
or the others anywhere outside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about the React Spectrum implementation for now. If it's added the prop, lets go ahead and Omit
it for the React Spectrum implementation
let isFocusedRef = useRef(false); | ||
let {focusProps} = useFocus({ | ||
isDisabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should always be enabled, otherwise you could end up in a scenario where the isDisabled
prop is toggled, but focus occurred while disabled, then the isFocusedRef wouldn't be correct.
We're not sending any focus callbacks into useClipboard
, so it won't be a problem of calling onFocus
or the others anywhere outside.
@@ -42,11 +42,17 @@ export interface DropZoneRenderProps { | |||
isDropTarget: boolean | |||
} | |||
|
|||
export interface DropZoneProps extends Omit<DropOptions, 'getDropOperationForPoint' | 'ref' | 'hasDropButton'>, HoverEvents, RenderProps<DropZoneRenderProps>, SlotProps, AriaLabelingProps {} | |||
export interface DropZoneProps extends Omit<DropOptions, 'getDropOperationForPoint' | 'ref' | 'hasDropButton'>, HoverEvents, RenderProps<DropZoneRenderProps>, SlotProps, AriaLabelingProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we'd also like to add isDisabled
to DropZoneRenderProps
and then also add data-disabled
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed it in the following commit:
GET_BUILD |
Build successful! 🎉 |
GET_BUILD |
Build successful! 🎉 |
## API Changes
unknown top level export { type: 'any' } @react-aria/dndDropOptions DropOptions {
getDropOperation?: (IDragTypes, Array<DropOperation>) => DropOperation
getDropOperationForPoint?: (IDragTypes, Array<DropOperation>, number, number) => DropOperation
hasDropButton?: boolean
+ isDisabled?: boolean
onDrop?: (DropEvent) => void
onDropEnter?: (DropEnterEvent) => void
onDropExit?: (DropExitEvent) => void
onDropMove?: (DropMoveEvent) => void
}
it changed:
ClipboardProps ClipboardProps {
getItems?: () => Array<DragItem>
+ isDisabled?: boolean
onCopy?: () => void
onCut?: () => void
onPaste?: (Array<DropItem>) => void
} it changed:
|
Closes #5938
To enable the
isDisabled
prop in DropZone, I've extendedisDisabled
support to several internal hooks. This update activatesisDisabled
for React Spectrum's DropZone as well. If this implementation poses no issues, I plan to add unit tests for it in React Spectrum's DropZone. I welcome any feedback.✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: