Skip to content

Commit

Permalink
Fix(web-react): FileUploaderInput className #DS-1508
Browse files Browse the repository at this point in the history
  • Loading branch information
curdaj committed Oct 23, 2024
1 parent 4681801 commit d6b6aa8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import classNames from 'classnames';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useDeprecationMessage, useStyleProps } from '../../hooks';
import { SpiritFileUploaderInputProps } from '../../types';
import { HelperText, ValidationText, useAriaIds } from '../Field';
Expand All @@ -11,6 +11,7 @@ import { useFileUploaderInput } from './useFileUploaderInput';
import { useFileUploaderStyleProps } from './useFileUploaderStyleProps';

const FileUploaderInput = (props: SpiritFileUploaderInputProps) => {
const [isDragAndDropSupported, setIsDragAndDropSupported] = useState(false);
const {
accept,
'aria-describedby': ariaDescribedBy = '',
Expand All @@ -34,10 +35,6 @@ const FileUploaderInput = (props: SpiritFileUploaderInputProps) => {
validationText,
...restProps
} = props;

const isDragAndDropSupported =
typeof document !== 'undefined' ? 'draggable' in document.createElement('span') : false;

const {
isDisabledByQueueLimitBehavior,
isDragging,
Expand Down Expand Up @@ -67,9 +64,12 @@ const FileUploaderInput = (props: SpiritFileUploaderInputProps) => {
validationState,
});
const { styleProps, props: transferProps } = useStyleProps(restProps);

const [ids, register] = useAriaIds(ariaDescribedBy);

useEffect(() => {
setIsDragAndDropSupported('draggable' in document.createElement('span'));
}, []);

useDeprecationMessage({
method: 'custom',
trigger: !id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
import { validationTextPropsTest } from '../../../../tests/providerTests/validationTextPropsTest';
import FileUploaderInput from '../FileUploaderInput';
import '@testing-library/jest-dom';

describe('FileUploaderInput', () => {
classNamePrefixProviderTest(FileUploaderInput, 'FileUploaderInput');

restPropsTest(FileUploaderInput, 'div');

validationTextPropsTest(FileUploaderInput, '.FileUploaderInput__validationText');

it('should have drag-and-drop class in Client component', () => {
render(<FileUploaderInput id="test-uploader" name="test-uploader" label="upload" data-testid="test" />);

const dropZone = screen.getAllByTestId('test')[0];

expect(dropZone).toHaveClass('has-drag-and-drop');
});

it('should not have drag-and-drop class in Server component', () => {
const container = renderToString(
<FileUploaderInput id="test-uploader" name="test-uploader" label="upload" data-testid="test" />,
);

expect(container).not.toContain('has-drag-and-drop');
});
});

0 comments on commit d6b6aa8

Please sign in to comment.