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

Add disabled prop to ColorInput.vue #12283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions shell/components/form/ColorInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export default {
componentTestid: {
type: String,
default: 'color-input'
},

disabled: {
type: Boolean,
default: false,
}
},

Expand All @@ -56,6 +61,12 @@ export default {
*/
inputValue() {
return this.value ? this.value : this.defaultValue;
},

isDisabled() {
const disabled = this.disabled;

return this.mode !== this.editMode || disabled;
}
},

Expand All @@ -69,7 +80,7 @@ export default {
<template>
<div
class="color-input"
:class="{[mode]:mode, disabled: mode !== editMode}"
:class="{[mode]:mode, disabled: isDisabled}"
:data-testid="componentTestid + '-color-input'"
>
<label class="text-label"><t
Expand All @@ -89,7 +100,7 @@ export default {
<input
ref="input"
type="color"
:disabled="mode !== editMode"
:disabled="isDisabled"
:value="inputValue"
@input="$emit('update:value', $event.target.value)"
>
Expand Down
27 changes: 27 additions & 0 deletions shell/components/form/__tests__/ColorInput.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { shallowMount } from '@vue/test-utils';
import ColorInput from '@shell/components/form/ColorInput.vue';

describe('colorInput.vue', () => {
it('disables the input when disabled prop is true', () => {
const wrapper = shallowMount(
ColorInput,
{ props: { disabled: true } }
);

const colorWrapper = wrapper.find('.color-input');
const colorInput = wrapper.find('input');

expect(colorWrapper.classes()).toContain('disabled');
expect(Object.keys(colorInput.attributes())).toContain('disabled');
});

it('defaults to enabled when no disabled prop is passed', () => {
const wrapper = shallowMount(ColorInput);

const colorWrapper = wrapper.find('.color-input');
const colorInput = wrapper.find('input');

expect(colorWrapper.classes()).not.toContain('disabled');
expect(Object.keys(colorInput.attributes())).not.toContain('disabled');
});
});
Loading