|
8 | 8 |
|
9 | 9 | import {SignalLike, WritableSignalLike} from '../signal-like/signal-like';
|
10 | 10 |
|
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', |
16 | 14 | TREE = 'tree',
|
17 | 15 | GRID = 'grid',
|
18 | 16 | DIALOG = 'dialog',
|
19 | 17 | LISTBOX = 'listbox',
|
20 | 18 | }
|
21 | 19 |
|
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 |
| - |
28 | 20 | /** Represents the inputs for the PopupControl behavior. */
|
29 | 21 | export interface PopupControlInputs {
|
30 |
| - /** The element that serves as the popup. */ |
31 |
| - popup: SignalLike<Popup>; |
32 |
| - |
33 | 22 | /* Refers to the element that serves as the popup. */
|
34 | 23 | controls: SignalLike<string>;
|
35 | 24 |
|
36 | 25 | /* Whether the popup is open or closed. */
|
37 | 26 | expanded: WritableSignalLike<boolean>;
|
38 | 27 |
|
39 | 28 | /* Corresponds to the popup type. */
|
40 |
| - hasPopup: SignalLike<ComboboxPopupTypes>; |
| 29 | + hasPopup: SignalLike<PopupTypes>; |
41 | 30 | }
|
42 | 31 |
|
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. */ |
48 | 33 | export class PopupControl {
|
49 | 34 | /** The inputs for the popup behavior, containing the `expanded` state signal. */
|
50 | 35 | constructor(readonly inputs: PopupControlInputs) {}
|
51 | 36 |
|
52 | 37 | /** Opens the popup by setting the expanded state to true. */
|
53 | 38 | open(): void {
|
54 | 39 | this.inputs.expanded.set(true);
|
55 |
| - this.inputs.popup().inert.set(false); |
56 | 40 | }
|
57 | 41 |
|
58 | 42 | /** Closes the popup by setting the expanded state to false. */
|
59 | 43 | close(): void {
|
60 | 44 | this.inputs.expanded.set(false);
|
61 |
| - this.inputs.popup().inert.set(true); |
62 | 45 | }
|
63 | 46 |
|
64 | 47 | /** Toggles the popup's expanded state. */
|
65 | 48 | toggle(): void {
|
66 | 49 | const expanded = !this.inputs.expanded();
|
67 | 50 | this.inputs.expanded.set(expanded);
|
68 |
| - this.inputs.popup().inert.set(!expanded); |
69 | 51 | }
|
70 | 52 | }
|
0 commit comments