Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(FileInput): a busy or disabled dropzone refuses the drag with the no-drop cursor (#9946)

Harjoth Khara0a039e7c9937
diff --git a/.changeset/fileinput-busy-dropzone-no-drop.md b/.changeset/fileinput-busy-dropzone-no-drop.md
new file mode 100644
index 0000000000..e0693211e7
--- /dev/null
+++ b/.changeset/fileinput-busy-dropzone-no-drop.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] FileInput: a busy or disabled dropzone now shows the no-drop cursor for a dragged file instead of the copy cursor, and the browser no longer delivers a drop the zone would ignore.
+
+@harjothkhara
diff --git a/packages/core/src/FileInput/FileInput.test.tsx b/packages/core/src/FileInput/FileInput.test.tsx
index b65ce607e7..817a3f55bc 100644
--- a/packages/core/src/FileInput/FileInput.test.tsx
+++ b/packages/core/src/FileInput/FileInput.test.tsx
@@ -1125,6 +1125,49 @@ describe('FileInput', () => {
expect(screen.getByText('Drop files here')).toBeInTheDocument();
});
+ it.each([
+ ['busy', {isLoading: true}],
+ ['disabled', {isDisabled: true}],
+ ])(
+ 'refuses the drag with the no-drop effect while %s, and still cancels it',
+ (_state, state) => {
+ render(
+ <FileInput
+ label="Upload"
+ value={null}
+ onChange={vi.fn()}
+ mode="dropzone"
+ {...state}
+ />,
+ );
+ const trigger = screen.getByRole('button', {name: 'Upload'});
+ for (const type of ['dragEnter', 'dragOver'] as const) {
+ const dataTransfer = {dropEffect: 'copy', files: []};
+ const event = createEvent[type](trigger, {dataTransfer});
+ fireEvent(trigger, event);
+ expect(dataTransfer.dropEffect).toBe('none');
+ expect(event.defaultPrevented).toBe(true);
+ }
+ },
+ );
+
+ it('keeps the copy effect for an idle dropzone', () => {
+ render(
+ <FileInput
+ label="Upload"
+ value={null}
+ onChange={vi.fn()}
+ mode="dropzone"
+ />,
+ );
+ const trigger = screen.getByRole('button', {name: 'Upload'});
+ for (const type of ['dragEnter', 'dragOver'] as const) {
+ const dataTransfer = {dropEffect: 'copy', files: []};
+ fireEvent(trigger, createEvent[type](trigger, {dataTransfer}));
+ expect(dataTransfer.dropEffect).toBe('copy');
+ }
+ });
+
it('blocks a second pick while changeAction is pending and allows picking again after settlement', async () => {
let finish: () => void = () => {};
const pending = new Promise<void>(resolve => {
diff --git a/packages/core/src/FileInput/FileInput.tsx b/packages/core/src/FileInput/FileInput.tsx
index 06ea631371..9aca4a5921 100644
--- a/packages/core/src/FileInput/FileInput.tsx
+++ b/packages/core/src/FileInput/FileInput.tsx
@@ -754,7 +754,14 @@ export function FileInput({
(e: DragEvent) => {
e.preventDefault();
e.stopPropagation();
- if (!isSelectionDisabled && mode === 'dropzone') {
+ if (isSelectionDisabled) {
+ // A cancelled dragover with the default effect makes the zone a drop
+ // target.
+ // The 'none' effect shows the no-drop cursor and stops the drop.
+ if (e.dataTransfer) {
+ e.dataTransfer.dropEffect = 'none';
+ }
+ } else if (mode === 'dropzone') {
setIsDragOver(true);
}
},
@@ -765,7 +772,14 @@ export function FileInput({
(e: DragEvent) => {
e.preventDefault();
e.stopPropagation();
- if (!isSelectionDisabled && mode === 'dropzone') {
+ if (isSelectionDisabled) {
+ // A cancelled dragover with the default effect makes the zone a drop
+ // target.
+ // The 'none' effect shows the no-drop cursor and stops the drop.
+ if (e.dataTransfer) {
+ e.dataTransfer.dropEffect = 'none';
+ }
+ } else if (mode === 'dropzone') {
setIsDragOver(true);
}
},