Skip to content

Commit

Permalink
fix(rdom-components): update dropdown args & attrib handling
Browse files Browse the repository at this point in the history
- update static/dynamicDropdown()
- allow user attribs to supply onchange handler
  • Loading branch information
postspectacular committed Mar 30, 2023
1 parent db9d2a1 commit f2bd62b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/rdom-components/src/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Fn } from "@thi.ng/api";
import { option, select, type SelectAttribs } from "@thi.ng/hiccup-html/forms";
import { $input } from "@thi.ng/rdom/event";
import { $list } from "@thi.ng/rdom/list";
import type { ISubscribable, Subscription } from "@thi.ng/rstream";
import type { ISubscribable, ISubscription } from "@thi.ng/rstream";

export interface DropdownOpts<T> {
attribs: Partial<SelectAttribs>;
Expand All @@ -12,7 +12,7 @@ export interface DropdownOpts<T> {

export const dynamicDropdown = <T = string, S extends string = string>(
items: ISubscribable<T[]>,
sel: Subscription<S, S>,
sel: ISubscription<S, S>,
opts?: Partial<DropdownOpts<T>>
) => {
opts = {
Expand All @@ -23,14 +23,14 @@ export const dynamicDropdown = <T = string, S extends string = string>(
return $list<T>(
items,
"select",
{ ...opts!.attribs, onchange: $input(sel) },
{ onchange: $input(sel), ...opts!.attribs },
$option(sel, <Required<DropdownOpts<T>>>opts)
);
};

export const staticDropdown = <T = string, S extends string = string>(
items: T[],
sel: Subscription<S, S>,
sel: ISubscription<S, S>,
opts?: Partial<DropdownOpts<T>>
) => {
opts = {
Expand All @@ -39,14 +39,14 @@ export const staticDropdown = <T = string, S extends string = string>(
...opts,
};
return select(
{ ...opts.attribs, onchange: $input(sel) },
{ onchange: $input(sel), ...opts.attribs },
...items.map($option(sel, <Required<DropdownOpts<T>>>opts))
);
};

const $option =
<T, S extends string>(
sel: Subscription<S, S>,
sel: ISubscription<S, S>,
{ label, value }: DropdownOpts<T>
) =>
(x: T) => {
Expand Down

0 comments on commit f2bd62b

Please sign in to comment.