@sonardigital/carbon-ui 1.2.8 → 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.8",
3
+ "version": "1.2.10",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -1,7 +1,15 @@
1
- import { Stack, TextField, TextFieldProps } from '@mui/material';
1
+ import {
2
+ ClickAwayListener,
3
+ IconButton,
4
+ Stack,
5
+ TextField,
6
+ TextFieldProps,
7
+ } from '@mui/material';
2
8
  import { Controller } from 'react-hook-form';
3
9
  import { FormLabel } from '../layout';
4
10
  import { FormError } from '../layout/FormError';
11
+ import { useState } from 'react';
12
+ import { RiCloseFill } from 'react-icons/ri';
5
13
 
6
14
  interface FormInputProps extends TextFieldProps<'standard'> {
7
15
  name: string;
@@ -13,13 +21,31 @@ export function FormInput({
13
21
  label,
14
22
  ...props
15
23
  }: FormInputProps): React.ReactElement {
24
+ const [isFocused, setIsFocused] = useState(false);
16
25
  return (
17
26
  <Controller
18
27
  name={name}
19
28
  render={({ field, fieldState }) => (
20
29
  <FormLabel label={label}>
21
30
  <Stack gap={0.8}>
22
- <TextField {...field} {...props} />
31
+ <ClickAwayListener onClickAway={() => setIsFocused(false)}>
32
+ <TextField
33
+ {...field}
34
+ {...props}
35
+ onFocus={() => setIsFocused(true)}
36
+ InputProps={{
37
+ ...props.InputProps,
38
+ endAdornment: isFocused && field.value && (
39
+ <IconButton
40
+ size="medium"
41
+ onClick={() => setIsFocused(false)}
42
+ >
43
+ <RiCloseFill size={18} />
44
+ </IconButton>
45
+ ),
46
+ }}
47
+ />
48
+ </ClickAwayListener>
23
49
  {fieldState.error && (
24
50
  <FormError label={fieldState.error?.message ?? ''} />
25
51
  )}
@@ -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
  }