Skip to content

Commit

Permalink
fix: APP-2817 - Remove brackets from maxlength tip, only show tip if …
Browse files Browse the repository at this point in the history
…no alert (#65)
  • Loading branch information
thekidnamedkd authored Jan 23, 2024
1 parent bb3a152 commit bb49d33
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Minimum `tailwindcss` version required
- Fix disabled input style on Firefox
- Max Length on inputs is restyle, only shows if no alert

### Added

Expand Down
20 changes: 18 additions & 2 deletions src/components/input/inputContainer/inputContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ describe('<InputContainer /> component', () => {
const maxLength = 100;
const inputLength = 47;
render(createTestComponent({ maxLength, inputLength }));
expect(screen.getByText(`[${inputLength}/${maxLength}]`)).toBeInTheDocument();
expect(screen.getByText(`${inputLength}/${maxLength}`)).toBeInTheDocument();
});

it('adds a shake animation when the input length is equal to the max length property', () => {
const maxLength = 10;
const inputLength = 10;
render(createTestComponent({ maxLength, inputLength }));
expect(screen.getByText(`[${inputLength}/${maxLength}]`).className).toContain('shake');
expect(screen.getByText(`${inputLength}/${maxLength}`).className).toContain('shake');
});

it('renders the input alert when defined', () => {
Expand All @@ -59,4 +59,20 @@ describe('<InputContainer /> component', () => {
expect(screen.getByRole('alert')).toBeInTheDocument();
expect(screen.getByText(alert.message)).toBeInTheDocument();
});

it('renders the input alert when both alert and maxLength properties are set, and only displays the Alert', () => {
const alert = {
message: 'input-alert-message',
variant: 'critical' as const,
};
const maxLength = 100;
const inputLength = 47;

render(createTestComponent({ alert, maxLength, inputLength }));

expect(screen.getByRole('alert')).toBeInTheDocument();
expect(screen.getByText(alert.message)).toBeInTheDocument();

expect(screen.queryByText(`${inputLength}/${maxLength}`)).not.toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions src/components/input/inputContainer/inputContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export const InputContainer: React.FC<IInputContainerProps> = (props) => {
</label>
)}
<div className={containerClasses}>{children}</div>
{maxLength != null && (
{maxLength != null && !alert && (
<p className={counterClasses}>
[{inputLength}/{maxLength}]
{inputLength}/{maxLength}
</p>
)}
{alert && <AlertInline variant={alert.variant} message={alert.message} />}
Expand Down

0 comments on commit bb49d33

Please sign in to comment.