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

Add support for DropZone isDisabled prop #5958

Merged
merged 11 commits into from
Feb 29, 2024

Conversation

ryo-manba
Copy link
Contributor

Closes #5938

To enable the isDisabled prop in DropZone, I've extended isDisabled support to several internal hooks. This update activates isDisabled 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:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

  1. Visit http://localhost:9003/?path=/story/react-aria-components--dropzone-with-render-props&providerSwitcher-express=false&strict=true.
  2. In the Controls tab, set isDisabled to true.
  3. Verify that drag-and-drop with the mouse is disabled.
  4. Verify that pasting from the clipboard is not possible.
  5. Verify that the DropZone cannot receive focus.

🧢 Your Project:

Copy link
Member

@reidbarber reidbarber left a 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},
Copy link
Member

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:

Suggested change
dropButtonProps: {disabled: true},
dropButtonProps: {isDisabled: true},

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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>
Copy link
Member

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,
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@snowystinger snowystinger left a 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,
Copy link
Member

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 {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reidbarber
Copy link
Member

GET_BUILD

@rspbot
Copy link

rspbot commented Feb 28, 2024

reidbarber
reidbarber previously approved these changes Feb 28, 2024
@snowystinger
Copy link
Member

GET_BUILD

@rspbot
Copy link

rspbot commented Feb 28, 2024

@rspbot
Copy link

rspbot commented Feb 28, 2024

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@react-aria/dnd

DropOptions

 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:

  • useDrop

ClipboardProps

 ClipboardProps {
   getItems?: () => Array<DragItem>
+  isDisabled?: boolean
   onCopy?: () => void
   onCut?: () => void
   onPaste?: (Array<DropItem>) => void
 }

it changed:

  • useClipboard

@snowystinger snowystinger merged commit 3492443 into adobe:main Feb 29, 2024
27 checks passed
@ryo-manba ryo-manba deleted the feat/dropzone-disabled branch February 29, 2024 00:11
@yihuiliao yihuiliao mentioned this pull request Apr 19, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RAC] DropZone isDisabled prop
5 participants