Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: APP-2817 - Remove brackets from maxlength tip, only show tip if no alert #65

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading