Skip to content

Commit 3bda789

Browse files
feat: fluid state for combobox (#3010)
Co-authored-by: Akshat Patel <[email protected]>
1 parent ee240f2 commit 3bda789

File tree

4 files changed

+183
-36
lines changed

4 files changed

+183
-36
lines changed

package-lock.json

Lines changed: 151 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"@angular/platform-browser-dynamic": "14.3.0",
8787
"@angular/router": "14.3.0",
8888
"@babel/core": "7.9.6",
89-
"@carbon/styles": "1.67.0",
89+
"@carbon/styles": "1.70.0",
9090
"@carbon/themes": "11.24.0",
9191
"@commitlint/cli": "17.0.3",
9292
"@commitlint/config-conventional": "17.0.3",

src/combobox/combobox.component.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ import { Observable } from "rxjs";
4040
@Component({
4141
selector: "cds-combo-box, ibm-combo-box",
4242
template: `
43-
<div class="cds--list-box__wrapper">
43+
<div
44+
class="cds--list-box__wrapper"
45+
[ngClass]="{
46+
'cds--list-box__wrapper--fluid': fluid,
47+
'cds--list-box__wrapper--fluid--invalid': fluid && invalid,
48+
'cds--list-box__wrapper--fluid--focus': fluid && _isFocused
49+
}">
4450
<label
4551
*ngIf="label"
4652
[for]="id"
@@ -64,7 +70,8 @@ import { Observable } from "rxjs";
6470
'cds--list-box--lg': size === 'lg',
6571
'cds--list-box--disabled': disabled,
6672
'cds--combo-box--readonly': readonly,
67-
'cds--combo-box--warning cds--list-box--warning': warn
73+
'cds--combo-box--warning cds--list-box--warning': warn,
74+
'cds--list-box--invalid': invalid
6875
}"
6976
class="cds--list-box cds--combo-box"
7077
[attr.data-invalid]="(invalid ? true : null)">
@@ -109,7 +116,8 @@ import { Observable } from "rxjs";
109116
[disabled]="disabled"
110117
[readOnly]="readonly"
111118
(input)="onSearch($event.target.value)"
112-
(blur)="onBlur()"
119+
(focus)="fluid ? handleFocus($event) : null"
120+
(blur)="fluid ? handleFocus($event) : onBlur()"
113121
(keydown.enter)="onSubmit($event)"
114122
[value]="selectedValue"
115123
class="cds--text-input"
@@ -166,8 +174,9 @@ import { Observable } from "rxjs";
166174
<ng-content *ngIf="open"></ng-content>
167175
</div>
168176
</div>
177+
<hr *ngIf="fluid" class="cds--list-box__divider" />
169178
<div
170-
*ngIf="helperText && !invalid && !warn"
179+
*ngIf="helperText && !invalid && !warn && !fluid"
171180
class="cds--form__helper-text"
172181
[ngClass]="{'cds--form__helper-text--disabled': disabled}">
173182
<ng-container *ngIf="!isTemplate(helperText)">{{helperText}}</ng-container>
@@ -368,6 +377,10 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
368377
* Set to `true` for readonly state.
369378
*/
370379
@Input() readonly = false;
380+
/**
381+
* Experimental: enable fluid state
382+
*/
383+
@Input() fluid = false;
371384
/**
372385
* Emits a ListItem
373386
*
@@ -426,7 +439,6 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
426439
@ViewChild("input", { static: true }) input: ElementRef;
427440
@ViewChild("listbox", { static: true }) listbox: ElementRef;
428441
@HostBinding("class.cds--list-box__wrapper") hostClass = true;
429-
@HostBinding("style.display") display = "block";
430442

431443
public open = false;
432444

@@ -456,6 +468,8 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
456468
protected _clearSelectionTitle = this.i18n.getOverridable("COMBOBOX.CLEAR_SELECTED");
457469
protected _clearSelectionAria = this.i18n.getOverridable("COMBOBOX.A11Y.CLEAR_SELECTED");
458470

471+
protected _isFocused = false;
472+
459473
/**
460474
* Creates an instance of ComboBox.
461475
*/
@@ -877,6 +891,10 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
877891
}
878892
}
879893

894+
handleFocus(event: FocusEvent) {
895+
this._isFocused = event.type === "focus";
896+
}
897+
880898
protected updateSelected() {
881899
const selected = this.view.getSelected();
882900
if (this.type === "multi") {

src/combobox/combobox.stories.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export default {
7272
dropUp: false,
7373
selectionFeedback: "top-after-reopen",
7474
size: "md",
75-
theme: "dark"
75+
theme: "dark",
76+
fluid: false
7677
},
7778
argTypes: {
7879
size: {
@@ -119,6 +120,7 @@ const Template = (args) => ({
119120
[items]="items"
120121
[theme]="theme"
121122
[dropUp]="dropUp"
123+
[fluid]="fluid"
122124
(selected)="selected($event)"
123125
(submit)="submit($event)"
124126
(search)="search($event)"
@@ -176,6 +178,10 @@ Dynamic.parameters = {
176178
}
177179
};
178180

181+
export const Fluid = Template.bind({});
182+
Fluid.args = {
183+
fluid: true
184+
};
179185

180186
const MultiTemplate = (args) => ({
181187
props: args,
@@ -196,6 +202,7 @@ const MultiTemplate = (args) => ({
196202
[selectionFeedback]="selectionFeedback"
197203
[dropUp]="dropUp"
198204
[appendInline]="appendInline"
205+
[fluid]="fluid"
199206
type="multi"
200207
(selected)="selected($event)"
201208
(submit)="submit($event)"

0 commit comments

Comments
 (0)