Skip to content

Commit

Permalink
fix(input/textarea): Fix maxLength console warning (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvalaura authored Jul 10, 2023
1 parent c49213f commit 1fa916b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/maxLength-warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': patch
---

fix(Input/Textarea): Fix `maxLength` console warning regarding passing a boolean attribute
4 changes: 3 additions & 1 deletion packages/react-magma-dom/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(

const maxCharacters = typeof maxCount === 'number' ? maxCount : maxLength;

const maxLengthNum = !hasCharacterCounter && maxLength ? maxLength : undefined;

const isInverse = useIsInverse(props.isInverse);

const [characterLength, setCharacterLength] = useState(
Expand Down Expand Up @@ -103,7 +105,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
inputSize={inputSize}
inputLength={characterLength}
isInverse={isInverse}
maxLength={!hasCharacterCounter && maxLength}
maxLength={maxLengthNum}
onChange={handleChange}
onClear={handleClear}
ref={ref}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-magma-dom/src/components/InputBase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ export const InputBase = React.forwardRef<HTMLInputElement, InputBaseProps>(
string | ReadonlyArray<string> | number
>(props.defaultValue || props.value || '');

const maxLengthNum = !hasCharacterCounter && maxLength ? maxLength : undefined;

React.useEffect(() => {
if (props.value !== undefined && props.value !== null) {
setValue(props.value);
Expand Down Expand Up @@ -623,7 +625,7 @@ export const InputBase = React.forwardRef<HTMLInputElement, InputBaseProps>(
isPredictive={isPredictive}
hasError={hasError}
ref={ref}
maxLength={!hasCharacterCounter && maxLength}
maxLength={maxLengthNum}
onChange={handleChange}
style={inputStyle}
theme={theme}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-magma-dom/src/components/Textarea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
const descriptionId = errorMessage || helperMessage ? `${id}__desc` : null;
const maxCharacters = typeof maxCount === 'number' ? maxCount : maxLength;

const maxLengthNum = !hasCharacterCounter && maxLength ? maxLength : undefined;

const [value, setValue] = React.useState<
string | ReadonlyArray<string> | number
>(props.defaultValue || props.value || '');
Expand Down Expand Up @@ -130,7 +132,7 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
(hasCharacterCounter && characterLength > maxCharacters)
}
id={id}
maxLength={!hasCharacterCounter && maxLength}
maxLength={maxLengthNum}
isInverse={isInverse}
onChange={handleChange}
ref={ref}
Expand Down

2 comments on commit 1fa916b

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.