Skip to content
Closed
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 addon/components/o-s-s/text-area.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="fx-1">
<div class="oss-textarea-container {{if this.hasError ' oss-textarea-container--errored'}}" ...attributes>
<div class="oss-textarea-container {{if @errorMessage ' oss-textarea-container--errored'}}" ...attributes>
<Textarea
@value={{@value}}
placeholder={{@placeholder}}
Expand Down
25 changes: 1 addition & 24 deletions addon/components/o-s-s/text-area.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ export default {
},
control: { type: 'text' }
},
hasError: {
description: 'Indicates if the textarea has an error state (adds danger-500 border)',
table: {
type: {
summary: 'boolean'
},
defaultValue: { summary: 'false' }
},
control: { type: 'boolean' }
},
onChange: {
description: 'Method called every time the textarea is updated',
table: {
Expand All @@ -104,30 +94,17 @@ const defaultArgs = {
disabled: false,
placeholder: 'this is the placeholder',
errorMessage: undefined,
hasError: false,
onChange: action('onChange')
};

const DefaultUsageTemplate = (args) => ({
template: hbs`
<OSS::TextArea @value={{this.value}} @disabled={{this.disabled}} @placeholder={{this.placeholder}}
@errorMessage={{this.errorMessage}} @hasError={{this.hasError}} @onChange={{this.onChange}} @rows={{this.rows}}
@errorMessage={{this.errorMessage}} @onChange={{this.onChange}} @rows={{this.rows}}
@resize={{this.resize}} />
`,
context: args
});

export const BasicUsage = DefaultUsageTemplate.bind({});
BasicUsage.args = defaultArgs;

export const WithError = DefaultUsageTemplate.bind({});
WithError.args = {
...defaultArgs,
hasError: true
};

export const WithErrorMessage = DefaultUsageTemplate.bind({});
WithErrorMessage.args = {
...defaultArgs,
errorMessage: 'This field is required'
};
6 changes: 0 additions & 6 deletions addon/components/o-s-s/text-area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface OSSTextAreaArgs {
value?: string;
disabled?: boolean;
errorMessage?: string;
hasError?: boolean;
placeholder?: string;
onChange?(value: string): void;
}
Expand All @@ -35,16 +34,11 @@ export default class OSSTextArea<T extends OSSTextAreaArgs> extends Component<T>
return this.args.resize;
}

get hasError(): boolean {
return this.args.hasError || !!this.args.errorMessage;
}

get computedClass(): string {
const classes: string[] = [];
if (this.resize === 'vertical') classes.push('oss-textarea--resize-v');
else if (this.resize === 'horizontal') classes.push('oss-textarea--resize-h');
else if (this.resize === 'none') classes.push('oss-textarea--resize-none');
if (this.hasError) classes.push('oss-textarea--errored');

return classes.join(' ');
}
Expand Down
40 changes: 0 additions & 40 deletions tests/integration/components/o-s-s/text-area-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,5 @@ module('Integration | Component | o-s-s/text-area', function (hooks) {
this.resize = 'NotACorrectValue';
await render(hbs`<OSS::TextArea @resize={{this.resize}} />`);
});

test('when @hasError is true, textarea has errored class', async function (assert) {
await render(hbs`<OSS::TextArea @hasError={{true}} />`);
assert.dom(this.textareaSelector).hasClass('oss-textarea--errored');
assert.dom('.oss-textarea-container').hasClass('oss-textarea-container--errored');
});

test('when @hasError is false, textarea does not have errored class', async function (assert) {
await render(hbs`<OSS::TextArea @hasError={{false}} />`);
assert.dom(this.textareaSelector).hasNoClass('oss-textarea--errored');
assert.dom('.oss-textarea-container').hasNoClass('oss-textarea-container--errored');
});

test('when @errorMessage is provided, textarea has errored class', async function (assert) {
await render(hbs`<OSS::TextArea @errorMessage="This is an error" />`);
assert.dom(this.textareaSelector).hasClass('oss-textarea--errored');
assert.dom('.oss-textarea-container').hasClass('oss-textarea-container--errored');
assert.dom('.font-color-error-500').exists();
assert.dom('.font-color-error-500').hasText('This is an error');
});

test('when @errorMessage is empty string, textarea does not have errored class', async function (assert) {
await render(hbs`<OSS::TextArea @errorMessage="" />`);
assert.dom(this.textareaSelector).hasNoClass('oss-textarea--errored');
assert.dom('.oss-textarea-container').hasNoClass('oss-textarea-container--errored');
});

test('when both @hasError and @errorMessage are provided, textarea has errored class', async function (assert) {
await render(hbs`<OSS::TextArea @hasError={{true}} @errorMessage="Error message" />`);
assert.dom(this.textareaSelector).hasClass('oss-textarea--errored');
assert.dom('.oss-textarea-container').hasClass('oss-textarea-container--errored');
assert.dom('.font-color-error-500').exists();
assert.dom('.font-color-error-500').hasText('Error message');
});

test('when neither @hasError nor @errorMessage are provided, textarea does not have errored class', async function (assert) {
await render(hbs`<OSS::TextArea />`);
assert.dom(this.textareaSelector).hasNoClass('oss-textarea--errored');
assert.dom('.oss-textarea-container').hasNoClass('oss-textarea-container--errored');
});
});
});
Loading