From 3108b90252e17435ba35154a12b1fda1630aed17 Mon Sep 17 00:00:00 2001 From: Eduard Marcinco Date: Fri, 22 Nov 2024 17:15:03 +0100 Subject: [PATCH] feat: fluid state for dropdown (#3008) Signed-off-by: Akshat Patel <38994122+Akshat55@users.noreply.github.com> Co-authored-by: Akshat Patel <38994122+Akshat55@users.noreply.github.com> --- src/dropdown/dropdown.component.ts | 83 ++++++++++++++++++++---------- src/dropdown/dropdown.stories.ts | 10 +++- 2 files changed, 66 insertions(+), 27 deletions(-) diff --git a/src/dropdown/dropdown.component.ts b/src/dropdown/dropdown.component.ts index 8f72f5366d..1fa5a48235 100644 --- a/src/dropdown/dropdown.component.ts +++ b/src/dropdown/dropdown.component.ts @@ -69,7 +69,7 @@ import { hasScrollableParents } from "carbon-components-angular/utils";
+ 'cds--list-box--expanded': !menuIsClosed, + 'cds--list-box--invalid': invalid + }" + [attr.data-invalid]="invalid ? true : null"> +
+ + + +
+
void = this._noop; + protected _isFocused = false; + // primarily used to capture and propagate input to `writeValue` before the content is available private _writtenValue: any = []; - protected get writtenValue() { - return this._writtenValue; - } - protected set writtenValue(val: any[]) { - if (val && val.length === 0) { - this.clearSelected(); - } - this._writtenValue = val; - } /** * Creates an instance of Dropdown. @@ -801,6 +825,13 @@ export class Dropdown implements OnInit, AfterContentInit, AfterViewInit, OnDest return value instanceof TemplateRef; } + handleFocus(event: FocusEvent) { + this._isFocused = event.type === "focus"; + if (event.type === "blur") { + this.onBlur(); + } + } + /** * Controls when it's needed to apply the selection feedback */ diff --git a/src/dropdown/dropdown.stories.ts b/src/dropdown/dropdown.stories.ts index 4d89220cdb..b7fbc62e65 100644 --- a/src/dropdown/dropdown.stories.ts +++ b/src/dropdown/dropdown.stories.ts @@ -65,7 +65,8 @@ export default { appendInline: false, dropUp: false, size: "md", - theme: "dark" + theme: "dark", + fluid: false }, argTypes: { type: { @@ -103,6 +104,7 @@ const Template = (args) => ({ placeholder="Select" [disabled]="disabled" [readonly]="readonly" + [fluid]="fluid" (selected)="selected($event)" (onClose)="onClose($event)"> @@ -111,6 +113,11 @@ const Template = (args) => ({ }); export const Basic = Template.bind({}); +export const Fluid = Template.bind({}); +Fluid.args = { + fluid: true +}; + const MultiTemplate = (args) => ({ props: args, template: ` @@ -131,6 +138,7 @@ const MultiTemplate = (args) => ({ placeholder="Select" [disabled]="disabled" [readonly]="readonly" + [fluid]="fluid" (selected)="selected($event)" (onClose)="onClose($event)">