From 0f4118bdbb9a6fe0297bad2ac3a76f4195152d0f Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 16 Jul 2023 08:07:49 +0800 Subject: [PATCH] Use select component from md3 --- components/BSelect.tsx | 48 +++++++--------------------------------- components/Md3Select.tsx | 2 ++ components/NewTask.tsx | 1 - 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/components/BSelect.tsx b/components/BSelect.tsx index 078fa5b..a0ce16d 100644 --- a/components/BSelect.tsx +++ b/components/BSelect.tsx @@ -1,6 +1,6 @@ import { Component, ContextType } from "preact"; -import Select from "preact-material-components/Select"; -import { Ref, StateUpdater, useRef } from "preact/hooks"; +import Md3Select from "./Md3Select.tsx"; +import { StateUpdater } from "preact/hooks"; import { BCtx } from "./BContext.tsx"; interface obj { @@ -15,10 +15,6 @@ type Props = { selectedValue?: T; /**@default {false}*/ disabled?: boolean; - /**@default {false}*/ - box?: boolean; - /**@default {false}*/ - outlined?: boolean; hintText?: string; set_value?: StateUpdater; name?: string; @@ -31,7 +27,6 @@ type State = { export default class BSelect extends Component, State> { static contextType = BCtx; declare context: ContextType; - ref: Ref(); return ( - + ); } get selectedIndex() { @@ -97,21 +82,4 @@ export default class BSelect extends Component, State> { }); } } - update(index: number) { - const e = this.ref?.current; - if (e) { - const b = e.base; - if (b) { - const t = b as HTMLElement; - const s = t.querySelector("select"); - if (s) { - s.selectedIndex = index; - } - } - } - } - update_value(value: T) { - const index = this.props.list.findIndex((v) => v.value === value); - if (index !== -1) this.update(index); - } } diff --git a/components/Md3Select.tsx b/components/Md3Select.tsx index 99e6fb1..08782a9 100644 --- a/components/Md3Select.tsx +++ b/components/Md3Select.tsx @@ -25,6 +25,7 @@ class Md3Option extends Component { } type Props = { + id?: string; children: VNode[] | VNode; /**@default {false} */ quick?: boolean; @@ -71,6 +72,7 @@ export default class Md3Select extends Component { const Select = MdOutlinedSelect.value; return (