Skip to content

Commit

Permalink
feat: fluid state for combobox (#3010)
Browse files Browse the repository at this point in the history
Co-authored-by: Akshat Patel <[email protected]>
  • Loading branch information
eduardmarcinco and Akshat55 authored Nov 22, 2024
1 parent ee240f2 commit 3bda789
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 36 deletions.
180 changes: 151 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"@angular/platform-browser-dynamic": "14.3.0",
"@angular/router": "14.3.0",
"@babel/core": "7.9.6",
"@carbon/styles": "1.67.0",
"@carbon/styles": "1.70.0",
"@carbon/themes": "11.24.0",
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
Expand Down
28 changes: 23 additions & 5 deletions src/combobox/combobox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ import { Observable } from "rxjs";
@Component({
selector: "cds-combo-box, ibm-combo-box",
template: `
<div class="cds--list-box__wrapper">
<div
class="cds--list-box__wrapper"
[ngClass]="{
'cds--list-box__wrapper--fluid': fluid,
'cds--list-box__wrapper--fluid--invalid': fluid && invalid,
'cds--list-box__wrapper--fluid--focus': fluid && _isFocused
}">
<label
*ngIf="label"
[for]="id"
Expand All @@ -64,7 +70,8 @@ import { Observable } from "rxjs";
'cds--list-box--lg': size === 'lg',
'cds--list-box--disabled': disabled,
'cds--combo-box--readonly': readonly,
'cds--combo-box--warning cds--list-box--warning': warn
'cds--combo-box--warning cds--list-box--warning': warn,
'cds--list-box--invalid': invalid
}"
class="cds--list-box cds--combo-box"
[attr.data-invalid]="(invalid ? true : null)">
Expand Down Expand Up @@ -109,7 +116,8 @@ import { Observable } from "rxjs";
[disabled]="disabled"
[readOnly]="readonly"
(input)="onSearch($event.target.value)"
(blur)="onBlur()"
(focus)="fluid ? handleFocus($event) : null"
(blur)="fluid ? handleFocus($event) : onBlur()"
(keydown.enter)="onSubmit($event)"
[value]="selectedValue"
class="cds--text-input"
Expand Down Expand Up @@ -166,8 +174,9 @@ import { Observable } from "rxjs";
<ng-content *ngIf="open"></ng-content>
</div>
</div>
<hr *ngIf="fluid" class="cds--list-box__divider" />
<div
*ngIf="helperText && !invalid && !warn"
*ngIf="helperText && !invalid && !warn && !fluid"
class="cds--form__helper-text"
[ngClass]="{'cds--form__helper-text--disabled': disabled}">
<ng-container *ngIf="!isTemplate(helperText)">{{helperText}}</ng-container>
Expand Down Expand Up @@ -368,6 +377,10 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
* Set to `true` for readonly state.
*/
@Input() readonly = false;
/**
* Experimental: enable fluid state
*/
@Input() fluid = false;
/**
* Emits a ListItem
*
Expand Down Expand Up @@ -426,7 +439,6 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
@ViewChild("input", { static: true }) input: ElementRef;
@ViewChild("listbox", { static: true }) listbox: ElementRef;
@HostBinding("class.cds--list-box__wrapper") hostClass = true;
@HostBinding("style.display") display = "block";

public open = false;

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

protected _isFocused = false;

/**
* Creates an instance of ComboBox.
*/
Expand Down Expand Up @@ -877,6 +891,10 @@ export class ComboBox implements OnChanges, AfterViewInit, AfterContentInit, OnD
}
}

handleFocus(event: FocusEvent) {
this._isFocused = event.type === "focus";
}

protected updateSelected() {
const selected = this.view.getSelected();
if (this.type === "multi") {
Expand Down
9 changes: 8 additions & 1 deletion src/combobox/combobox.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export default {
dropUp: false,
selectionFeedback: "top-after-reopen",
size: "md",
theme: "dark"
theme: "dark",
fluid: false
},
argTypes: {
size: {
Expand Down Expand Up @@ -119,6 +120,7 @@ const Template = (args) => ({
[items]="items"
[theme]="theme"
[dropUp]="dropUp"
[fluid]="fluid"
(selected)="selected($event)"
(submit)="submit($event)"
(search)="search($event)"
Expand Down Expand Up @@ -176,6 +178,10 @@ Dynamic.parameters = {
}
};

export const Fluid = Template.bind({});
Fluid.args = {
fluid: true
};

const MultiTemplate = (args) => ({
props: args,
Expand All @@ -196,6 +202,7 @@ const MultiTemplate = (args) => ({
[selectionFeedback]="selectionFeedback"
[dropUp]="dropUp"
[appendInline]="appendInline"
[fluid]="fluid"
type="multi"
(selected)="selected($event)"
(submit)="submit($event)"
Expand Down

0 comments on commit 3bda789

Please sign in to comment.