fix-file-upload (#1583)

* handle file upload more like the way rjsf core is now handling it w/ burnettk

* removed unused module w/ burnettk

* use onChangeOverride if given w/ burnettk

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2024-05-21 19:40:01 +00:00 committed by GitHub
parent fc74924a6d
commit a402bfc4fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 7 deletions

View File

@ -5,16 +5,13 @@ import {
RJSFSchema,
StrictRJSFSchema,
WidgetProps,
examplesId,
ariaDescribedByIds,
} from '@rjsf/utils';
import { parse } from 'date-fns';
import { useCallback } from 'react';
import { useDebouncedCallback } from 'use-debounce';
import {
DATE_FORMAT,
DATE_FORMAT_CARBON,
DATE_FORMAT_FOR_DISPLAY,
} from '../../../config';
import { DATE_FORMAT_CARBON, DATE_FORMAT_FOR_DISPLAY } from '../../../config';
import DateAndTimeService from '../../../services/DateAndTimeService';
import { getCommonAttributes } from '../../helpers';
@ -39,6 +36,7 @@ export default function BaseInputTemplate<
onBlur,
onFocus,
onChange,
onChangeOverride,
required,
options,
schema,
@ -154,6 +152,23 @@ export default function BaseInputTemplate<
/>
</DatePicker>
);
} else if (type === 'file') {
component = (
<input
id={id}
className="file-upload"
readOnly={readonly}
disabled={disabled}
autoFocus={autofocus}
value={value}
{...inputProps}
list={schema.examples ? examplesId<T>(id) : undefined}
onChange={onChangeOverride || _onChange}
onBlur={_onBlur}
onFocus={_onFocus}
aria-describedby={ariaDescribedByIds<T>(id, !!schema.examples)}
/>
);
} else {
component = (
<>
@ -165,9 +180,9 @@ export default function BaseInputTemplate<
invalid={commonAttributes.invalid}
invalidText={commonAttributes.errorMessageForField}
autoFocus={autofocus}
onChange={onChangeOverride || _onChange}
disabled={disabled || readonly}
value={value || value === 0 ? value : ''}
onChange={_onChange}
onBlur={_onBlur}
onFocus={_onFocus}
enableCounter={enableCounter}

View File

@ -44,6 +44,18 @@
padding-top: 8px;
}
.rjsf .file-upload {
padding-top: 8px;
padding-bottom: 8px;
font-size: 14px;
}
/* position the remove button to align with the file description */
.rjsf .file-info span div {
position: relative;
bottom: 6px;
left: 5px;
}
.rjsf .rjsf-field label {
font-weight: bolder;
}