Skip to content

Commit 3c13b8b

Browse files
julczkaiOvergaard
authored andcommitted
feat: 🐛 add disabled property to uui-combobox
1 parent 5b26c91 commit 3c13b8b

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

packages/uui-combobox/lib/uui-combobox.element.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
6767
margin-top: -1px;
6868
}
6969
70+
:host([disabled]) #caret {
71+
fill: var(--uui-color-disabled-contrast);
72+
}
73+
7074
#phone-wrapper {
7175
position: fixed;
7276
inset: 0;
@@ -142,6 +146,15 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
142146
@property({ type: String })
143147
public closeLabel = 'Close';
144148

149+
/**
150+
* Disables the uui-combobox.
151+
* @type {boolean}
152+
* @attr
153+
* @default false
154+
*/
155+
@property({ type: Boolean, reflect: true })
156+
disabled = false;
157+
145158
@query('#combobox-input')
146159
private _input!: HTMLInputElement;
147160

@@ -315,11 +328,12 @@ export class UUIComboboxElement extends FormControlMixin(LitElement) {
315328
type="text"
316329
.value=${this._displayValue}
317330
autocomplete="off"
331+
.disabled=${this.disabled}
318332
@click=${this._open}
319333
@input=${this._onInput}
320334
@keydown=${this._onKeyDown}>
321335
<slot name="input-prepend" slot="prepend"></slot>
322-
${this._renderClearButton()} ${this._renderCaret()}
336+
${this.disabled ? '' : this._renderClearButton()} ${this._renderCaret()}
323337
<slot name="input-append" slot="append"></slot>
324338
</uui-input>`;
325339
};

packages/uui-combobox/lib/uui-combobox.story.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export default {
1414
component: 'uui-combobox',
1515
args: {
1616
search: '',
17+
disabled: false,
18+
readonly: false,
1719
},
1820
parameters: {
1921
docs: {
@@ -99,6 +101,8 @@ const Template: Story = props => {
99101
displayValueMod,
100102
valueMod,
101103
renderMod,
104+
disabled,
105+
value,
102106
} = props;
103107

104108
const handleSearch = (e: any) => {
@@ -114,7 +118,9 @@ const Template: Story = props => {
114118
return html`<uui-combobox
115119
@change=${handleSelect}
116120
@search=${handleSearch}
117-
style="width: 250px">
121+
style="width: 250px"
122+
.disabled=${disabled}
123+
.value=${value}>
118124
<uui-combobox-list>
119125
${repeat(filter(options, search), (option: any, index: number) =>
120126
renderMod
@@ -163,6 +169,36 @@ AAAOverview.parameters = {
163169
},
164170
};
165171

172+
export const Disabled: Story = Template.bind({});
173+
Disabled.args = {
174+
options: fruits,
175+
filter: basicFilter,
176+
disabled: true,
177+
value: 'banana',
178+
};
179+
Disabled.parameters = {
180+
docs: {
181+
source: {
182+
code: `
183+
<uui-combobox style="width: 250px" disabled>
184+
<uui-combobox-list>
185+
<uui-combobox-list-option style="padding: 8px">
186+
apple
187+
</uui-combobox-list-option>
188+
<uui-combobox-list-option style="padding: 8px">
189+
orange
190+
</uui-combobox-list-option>
191+
<uui-combobox-list-option style="padding: 8px">
192+
lemon
193+
</uui-combobox-list-option>
194+
...
195+
</uui-combobox-list>
196+
</uui-combobox>
197+
`,
198+
},
199+
},
200+
};
201+
166202
export const CustomValue: Story = Template.bind({});
167203
CustomValue.args = {
168204
options: fruits,

packages/uui-combobox/lib/uui-combobox.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ describe('UUIComboboxElement', () => {
6262
it('has a value property', () => {
6363
expect(element).to.have.property('value');
6464
});
65+
it('has a disabled property', () => {
66+
expect(element).to.have.property('disabled');
67+
});
6568
});
6669

6770
describe('template', () => {

packages/uui/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
"path": "../uui-color-slider"
7272
},
7373
{
74-
"path": "../uui-color-swatches"
74+
"path": "../uui-color-swatch"
7575
},
7676
{
77-
"path": "../uui-color-swatch"
77+
"path": "../uui-color-swatches"
7878
},
7979
{
8080
"path": "../uui-combobox"

0 commit comments

Comments
 (0)