@rjsf/react-bootstrap 6.1.2 → 6.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/react-bootstrap",
3
- "version": "6.1.2",
3
+ "version": "6.2.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -61,8 +61,8 @@
61
61
  ]
62
62
  },
63
63
  "peerDependencies": {
64
- "@rjsf/core": "^6.x",
65
- "@rjsf/utils": "^6.x",
64
+ "@rjsf/core": "^6.2.x",
65
+ "@rjsf/utils": "^6.2.x",
66
66
  "react": ">=18",
67
67
  "react-bootstrap": "^2.x"
68
68
  },
@@ -71,10 +71,10 @@
71
71
  "node": ">=20"
72
72
  },
73
73
  "devDependencies": {
74
- "@rjsf/core": "^6.x",
75
- "@rjsf/snapshot-tests": "^6.x",
76
- "@rjsf/utils": "^6.x",
77
- "@rjsf/validator-ajv8": "^6.x",
74
+ "@rjsf/core": "^6.2.0",
75
+ "@rjsf/snapshot-tests": "^6.2.0",
76
+ "@rjsf/utils": "^6.2.0",
77
+ "@rjsf/validator-ajv8": "^6.2.0",
78
78
  "eslint": "^8.57.1",
79
79
  "react-bootstrap": "^2.10.10"
80
80
  },
@@ -1,4 +1,4 @@
1
- import { ChangeEvent, FocusEvent } from 'react';
1
+ import { ChangeEvent, FocusEvent, MouseEvent, useCallback } from 'react';
2
2
  import Form from 'react-bootstrap/Form';
3
3
  import {
4
4
  ariaDescribedByIds,
@@ -33,7 +33,9 @@ export default function BaseInputTemplate<
33
33
  rawErrors = [],
34
34
  children,
35
35
  extraProps,
36
+ registry,
36
37
  }: BaseInputTemplateProps<T, S, F>) {
38
+ const { ClearButton } = registry.templates.ButtonTemplates;
37
39
  const inputProps = {
38
40
  ...extraProps,
39
41
  ...getInputProps<T, S, F>(schema, type, options),
@@ -42,6 +44,14 @@ export default function BaseInputTemplate<
42
44
  onChange(value === '' ? options.emptyValue : value);
43
45
  const _onBlur = ({ target }: FocusEvent<HTMLInputElement>) => onBlur(id, target && target.value);
44
46
  const _onFocus = ({ target }: FocusEvent<HTMLInputElement>) => onFocus(id, target && target.value);
47
+ const _onClear = useCallback(
48
+ (e: MouseEvent) => {
49
+ e.preventDefault();
50
+ e.stopPropagation();
51
+ onChange(options.emptyValue ?? '');
52
+ },
53
+ [onChange, options.emptyValue],
54
+ );
45
55
 
46
56
  // const classNames = [rawErrors.length > 0 ? "is-invalid" : "", type === 'file' ? 'custom-file-label': ""]
47
57
  return (
@@ -63,6 +73,9 @@ export default function BaseInputTemplate<
63
73
  onFocus={_onFocus}
64
74
  aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
65
75
  />
76
+ {options.allowClearTextInputs && !readonly && !disabled && value && (
77
+ <ClearButton registry={registry} onClick={_onClear} />
78
+ )}
66
79
  {children}
67
80
  {Array.isArray(schema.examples) ? (
68
81
  <datalist id={examplesId(id)}>
@@ -4,6 +4,7 @@ import { IoIosCopy } from '@react-icons/all-files/io/IoIosCopy';
4
4
  import { IoIosRemove } from '@react-icons/all-files/io/IoIosRemove';
5
5
  import { AiOutlineArrowUp } from '@react-icons/all-files/ai/AiOutlineArrowUp';
6
6
  import { AiOutlineArrowDown } from '@react-icons/all-files/ai/AiOutlineArrowDown';
7
+ import { IoMdClose } from '@react-icons/all-files/io/IoMdClose';
7
8
 
8
9
  export type BootstrapIconButtonProps<
9
10
  T = any,
@@ -66,3 +67,12 @@ export function RemoveButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F
66
67
  />
67
68
  );
68
69
  }
70
+
71
+ export function ClearButton<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
72
+ props: BootstrapIconButtonProps<T, S, F>,
73
+ ) {
74
+ const {
75
+ registry: { translateString },
76
+ } = props;
77
+ return <IconButton title={translateString(TranslatableString.ClearButton)} {...props} icon={<IoMdClose />} />;
78
+ }
@@ -4,7 +4,7 @@ import ArrayFieldTemplate from '../ArrayFieldTemplate';
4
4
  import BaseInputTemplate from '../BaseInputTemplate/BaseInputTemplate';
5
5
  import DescriptionField from '../DescriptionField';
6
6
  import ErrorList from '../ErrorList';
7
- import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '../IconButton';
7
+ import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton, ClearButton } from '../IconButton';
8
8
  import FieldErrorTemplate from '../FieldErrorTemplate';
9
9
  import FieldHelpTemplate from '../FieldHelpTemplate';
10
10
  import FieldTemplate from '../FieldTemplate';
@@ -33,6 +33,7 @@ export function generateTemplates<
33
33
  MoveUpButton,
34
34
  RemoveButton,
35
35
  SubmitButton,
36
+ ClearButton,
36
37
  },
37
38
  DescriptionFieldTemplate: DescriptionField,
38
39
  ErrorListTemplate: ErrorList,
@@ -70,7 +70,7 @@ export default function WrapIfAdditionalTemplate<
70
70
  </Form.Group>
71
71
  </Col>
72
72
  <Col xs={6}>{children}</Col>
73
- <Col xs={1} className={`py-${padding} d-grid gap-2`} style={{ marginTop: `${margin}px` }}>
73
+ <Col xs={1} className={`py-${padding} d-grid gap-2`} style={{ marginTop: `${margin}px`, maxHeight: `2.5rem` }}>
74
74
  <RemoveButton
75
75
  id={buttonId(id, 'remove')}
76
76
  className='rjsf-object-property-remove w-100'