Skip to content

Commit c386241

Browse files
committed
fixup! feat(cdk-experimental/ui-patterns): add popup behavior
1 parent a6625a1 commit c386241

File tree

2 files changed

+8
-40
lines changed

2 files changed

+8
-40
lines changed

src/cdk-experimental/ui-patterns/behaviors/popup/popup.spec.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
*/
88

99
import {signal} from '@angular/core';
10-
import {ComboboxPopupTypes, PopupControl, PopupControlInputs} from './popup';
10+
import {PopupTypes, PopupControl, PopupControlInputs} from './popup';
1111

12-
type TestInputs = Partial<Pick<PopupControlInputs, 'popup' | 'expanded'>>;
12+
type TestInputs = Partial<Pick<PopupControlInputs, 'expanded'>>;
1313

1414
function getPopupControl(inputs: TestInputs = {}): PopupControl {
1515
const expanded = inputs.expanded || signal(false);
1616
const popup = signal({inert: signal(!expanded())});
1717
const controls = signal('popup-element-id');
18-
const hasPopup = signal(ComboboxPopupTypes.LISTBOX);
18+
const hasPopup = signal(PopupTypes.LISTBOX);
1919

2020
return new PopupControl({
21-
popup,
2221
controls,
2322
expanded,
2423
hasPopup,
@@ -31,12 +30,8 @@ describe('Popup Control', () => {
3130
const control = getPopupControl();
3231

3332
expect(control.inputs.expanded()).toBeFalse();
34-
expect(control.inputs.popup().inert()).toBeTrue();
35-
3633
control.open();
37-
3834
expect(control.inputs.expanded()).toBeTrue();
39-
expect(control.inputs.popup().inert()).toBeFalse();
4035
});
4136
});
4237

@@ -46,12 +41,8 @@ describe('Popup Control', () => {
4641
const control = getPopupControl({expanded});
4742

4843
expect(control.inputs.expanded()).toBeTrue();
49-
expect(control.inputs.popup().inert()).toBeFalse();
50-
5144
control.close();
52-
5345
expect(control.inputs.expanded()).toBeFalse();
54-
expect(control.inputs.popup().inert()).toBeTrue();
5546
});
5647
});
5748

@@ -60,17 +51,12 @@ describe('Popup Control', () => {
6051
const control = getPopupControl();
6152

6253
expect(control.inputs.expanded()).toBeFalse();
63-
expect(control.inputs.popup().inert()).toBeTrue();
64-
6554
control.toggle();
6655

6756
expect(control.inputs.expanded()).toBeTrue();
68-
expect(control.inputs.popup().inert()).toBeFalse();
69-
7057
control.toggle();
7158

7259
expect(control.inputs.expanded()).toBeFalse();
73-
expect(control.inputs.popup().inert()).toBeTrue();
7460
});
7561
});
7662
});

src/cdk-experimental/ui-patterns/behaviors/popup/popup.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,63 +8,45 @@
88

99
import {SignalLike, WritableSignalLike} from '../signal-like/signal-like';
1010

11-
/**
12-
* Represents the inputs required for a popup behavior.
13-
* It includes a signal for the expanded state and a reference to the popup element.
14-
*/
15-
export enum ComboboxPopupTypes {
11+
/** Valid popup types for aria-haspopup. */
12+
export enum PopupTypes {
13+
MENU = 'menu',
1614
TREE = 'tree',
1715
GRID = 'grid',
1816
DIALOG = 'dialog',
1917
LISTBOX = 'listbox',
2018
}
2119

22-
/** The element that serves as the popup. */
23-
export interface Popup {
24-
/** Whether the popup is interactive or not. */
25-
inert: WritableSignalLike<boolean>;
26-
}
27-
2820
/** Represents the inputs for the PopupControl behavior. */
2921
export interface PopupControlInputs {
30-
/** The element that serves as the popup. */
31-
popup: SignalLike<Popup>;
32-
3322
/* Refers to the element that serves as the popup. */
3423
controls: SignalLike<string>;
3524

3625
/* Whether the popup is open or closed. */
3726
expanded: WritableSignalLike<boolean>;
3827

3928
/* Corresponds to the popup type. */
40-
hasPopup: SignalLike<ComboboxPopupTypes>;
29+
hasPopup: SignalLike<PopupTypes>;
4130
}
4231

43-
/**
44-
* A behavior that manages the open/close state of a component.
45-
* It provides methods to open, close, and toggle the state,
46-
* which is controlled via a writable signal.
47-
*/
32+
/** A behavior that manages the open/close state of a component. */
4833
export class PopupControl {
4934
/** The inputs for the popup behavior, containing the `expanded` state signal. */
5035
constructor(readonly inputs: PopupControlInputs) {}
5136

5237
/** Opens the popup by setting the expanded state to true. */
5338
open(): void {
5439
this.inputs.expanded.set(true);
55-
this.inputs.popup().inert.set(false);
5640
}
5741

5842
/** Closes the popup by setting the expanded state to false. */
5943
close(): void {
6044
this.inputs.expanded.set(false);
61-
this.inputs.popup().inert.set(true);
6245
}
6346

6447
/** Toggles the popup's expanded state. */
6548
toggle(): void {
6649
const expanded = !this.inputs.expanded();
6750
this.inputs.expanded.set(expanded);
68-
this.inputs.popup().inert.set(!expanded);
6951
}
7052
}

0 commit comments

Comments
 (0)