@sonardigital/carbon-ui 1.2.9 → 1.2.10

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": "@sonardigital/carbon-ui",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -1,15 +1,14 @@
1
1
  import {
2
- FormControl,
2
+ ClickAwayListener,
3
3
  IconButton,
4
- InputAdornment,
5
4
  Stack,
6
5
  TextField,
7
6
  TextFieldProps,
8
- useFormControl,
9
7
  } from '@mui/material';
10
8
  import { Controller } from 'react-hook-form';
11
9
  import { FormLabel } from '../layout';
12
10
  import { FormError } from '../layout/FormError';
11
+ import { useState } from 'react';
13
12
  import { RiCloseFill } from 'react-icons/ri';
14
13
 
15
14
  interface FormInputProps extends TextFieldProps<'standard'> {
@@ -17,52 +16,40 @@ interface FormInputProps extends TextFieldProps<'standard'> {
17
16
  label: string;
18
17
  }
19
18
 
20
- function Adornment({
21
- children,
22
- }: {
23
- children: React.ReactNode;
24
- }): React.ReactNode {
25
- const { focused = false } = useFormControl() as { focused: boolean };
26
-
27
- return focused ? children : <></>;
28
- }
29
-
30
19
  export function FormInput({
31
20
  name,
32
21
  label,
33
22
  ...props
34
23
  }: FormInputProps): React.ReactElement {
24
+ const [isFocused, setIsFocused] = useState(false);
35
25
  return (
36
26
  <Controller
37
27
  name={name}
38
28
  render={({ field, fieldState }) => (
39
29
  <FormLabel label={label}>
40
- <FormControl>
41
- <Stack gap={0.8}>
30
+ <Stack gap={0.8}>
31
+ <ClickAwayListener onClickAway={() => setIsFocused(false)}>
42
32
  <TextField
43
33
  {...field}
44
34
  {...props}
35
+ onFocus={() => setIsFocused(true)}
45
36
  InputProps={{
46
37
  ...props.InputProps,
47
- endAdornment: (
48
- <Adornment>
49
- <InputAdornment position="end">
50
- <IconButton
51
- size="small"
52
- onClick={() => field.onChange(null)}
53
- >
54
- <RiCloseFill size={18} />
55
- </IconButton>
56
- </InputAdornment>
57
- </Adornment>
38
+ endAdornment: isFocused && field.value && (
39
+ <IconButton
40
+ size="medium"
41
+ onClick={() => setIsFocused(false)}
42
+ >
43
+ <RiCloseFill size={18} />
44
+ </IconButton>
58
45
  ),
59
46
  }}
60
47
  />
61
- {fieldState.error && (
62
- <FormError label={fieldState.error?.message ?? ''} />
63
- )}
64
- </Stack>
65
- </FormControl>
48
+ </ClickAwayListener>
49
+ {fieldState.error && (
50
+ <FormError label={fieldState.error?.message ?? ''} />
51
+ )}
52
+ </Stack>
66
53
  </FormLabel>
67
54
  )}
68
55
  />
@@ -40,7 +40,7 @@ export function SelectAutocomplete(
40
40
  onChange={(_, value) => value?.value && onChange(value.value)}
41
41
  getOptionLabel={option => option.label || ''}
42
42
  clearIcon={
43
- <IconButton size="small" onClick={() => onChange(null)}>
43
+ <IconButton size="medium" onClick={() => onChange(null)}>
44
44
  <RiCloseFill size={18} />
45
45
  </IconButton>
46
46
  }