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(TextInput): remove clear input button if TextInput is disabled #677

Merged
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
2 changes: 1 addition & 1 deletion src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const TextInput = (props: Props, ref: RefObject<HTMLInputElement>): ReactElement
maxLength={inputMaxLen}
aria-describedby={messages && !!messages.length ? messageId.current : undefined}
/>
{!!state.value && (
{!!state.value && !isDisabled && (
<ButtonSimple
className="clear-icon"
aria-label={clearAriaLabel}
Expand Down
38 changes: 38 additions & 0 deletions src/components/TextInput/TextInput.unit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ describe('<TextInput/>', () => {

expect(container).toMatchSnapshot();
});

it('should match snapshot with isDisabled', async () => {
expect.assertions(1);

const container = await mountComponent(<TextInput aria-label="text-input" isDisabled />);

expect(container).toMatchSnapshot();
});
});

describe('attributes', () => {
Expand Down Expand Up @@ -211,6 +219,36 @@ describe('<TextInput/>', () => {

expect(textInputComponent.props()['aria-describedby']).toBe(undefined);
});

it('should not have the clear input button displayed when value is empty', async () => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value="" />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(false);
});
dominiccarrington marked this conversation as resolved.
Show resolved Hide resolved

it.each(['hello world', '0', '123', ' '])(
'should have the clear input button displayed when not disabled (value = "%s")',
async (value) => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value={value} />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(true);
}
);

it.each(['', 'hello world', '0', '123', ' '])(
'should not have the clear input button displayed when isDisabled (value = "%s")',
async (value) => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value={value} isDisabled />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(false);
}
);
});

describe('actions', () => {
Expand Down
32 changes: 32 additions & 0 deletions src/components/TextInput/TextInput.unit.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,38 @@ exports[`<TextInput/> snapshot should match snapshot with inputMaxLen 1`] = `
</SSRProvider>
`;

exports[`<TextInput/> snapshot should match snapshot with isDisabled 1`] = `
<SSRProvider>
<TextInput
aria-label="text-input"
isDisabled={true}
>
<div
className="md-text-input-wrapper"
data-disabled={true}
data-focus={false}
data-level="none"
onClick={[Function]}
>
<div
className="md-text-input-container"
>
<input
aria-label="text-input"
disabled={true}
id="test-ID"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
readOnly={false}
type="text"
/>
</div>
</div>
</TextInput>
</SSRProvider>
`;

exports[`<TextInput/> snapshot should match snapshot with label 1`] = `
<SSRProvider>
<TextInput
Expand Down
Loading