Skip to content

Commit

Permalink
Merge branch 'main' into get-default-state-test-refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
heath-freenome authored Jan 24, 2025
2 parents 0f1a284 + 3f9760b commit 71cb9f0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ should change the heading of the (upcoming) version to include a major version b
## @rjsf/utils

- switch `lodash.isEqualWith` to `fast-equals.createCustomEqual` providing `areFunctionsEqual` assuming any functions are equal.
- Fixed issue with file accept attribute, fixing [#4404](https://github.com/rjsf-team/react-jsonschema-form/issues/4404).

## @rjsf/mui

- Fixed issue with file accept attribute, fixing [#4404](https://github.com/rjsf-team/react-jsonschema-form/issues/4404).

# 5.24.1

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/usage/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import * as precompiledValidator from 'path_to/yourCompiledSchema';

const validator = createPrecompiledValidator(precompiledValidator as ValidatorFunctions);

render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
render(<Form schema={yourSchema} validator={validator} />, document.getElementById('app'));
```

### Dynamically pre-compiling validators
Expand Down
17 changes: 6 additions & 11 deletions packages/mui/src/BaseInputTemplate/BaseInputTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,8 @@ export default function BaseInputTemplate<
} = props;
const inputProps = getInputProps<T, S, F>(schema, type, options);
// Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
const { step, min, max, ...rest } = inputProps;
const otherProps = {
inputProps: {
step,
min,
max,
...(schema.examples ? { list: examplesId<T>(id) } : undefined),
},
...rest,
};
const { step, min, max, accept, ...rest } = inputProps;
const htmlInputProps = { step, min, max, accept, ...(schema.examples ? { list: examplesId<T>(id) } : undefined) };
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
onChange(value === '' ? options.emptyValue : value);
const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
Expand All @@ -84,7 +76,10 @@ export default function BaseInputTemplate<
autoFocus={autofocus}
required={required}
disabled={disabled || readonly}
{...otherProps}
slotProps={{
htmlInput: htmlInputProps,
}}
{...rest}
value={value || value === 0 ? value : ''}
error={rawErrors.length > 0}
onChange={onChangeOverride || _onChange}
Expand Down
4 changes: 4 additions & 0 deletions packages/utils/src/getInputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ export default function getInputProps<
inputProps.autoComplete = options.autocomplete;
}

if (options.accept) {
inputProps.accept = options.accept as string;
}

return inputProps;
}
2 changes: 2 additions & 0 deletions packages/utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export type InputPropsType = Omit<RangeSpecType, 'step'> & {
step?: number | 'any';
/** Specifies the `autoComplete` value for an <input> element */
autoComplete?: HTMLInputElement['autocomplete'];
/** Specifies a filter for what file types the user can upload. */
accept?: HTMLInputElement['accept'];
};

/** Type describing an id used for a field in the `IdSchema` */
Expand Down
11 changes: 9 additions & 2 deletions packages/utils/test/getInputProps.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { getInputProps, RJSFSchema } from '../src';
import { getInputProps, RJSFSchema, UIOptionsType } from '../src';

describe('getInputProps', () => {
it('returns type=text when no other data is passed', () => {
expect(getInputProps({})).toEqual({ type: 'text' });
});
it('returns type and autoComplete from options when provided', () => {
const options = { inputType: 'password', autocomplete: 'on' };
const options: UIOptionsType = { inputType: 'password', autocomplete: 'on' };
expect(getInputProps({}, 'text', options)).toEqual({
type: options.inputType,
autoComplete: options.autocomplete,
});
});
it('returns type and accept from options when provided', () => {
const options: UIOptionsType = { accept: '.pdf' };
expect(getInputProps({}, 'file', options)).toEqual({
type: 'file',
accept: options.accept,
});
});
it('returns type=defaultType even when schema has type', () => {
const schema: RJSFSchema = {
type: 'number',
Expand Down

0 comments on commit 71cb9f0

Please sign in to comment.