{
- this.buttonRef.element!.focus();
- };
}
diff --git a/packages/duoyun-ui/src/elements/calendar.ts b/packages/duoyun-ui/src/elements/calendar.ts
index 723f49d3..0733aaeb 100644
--- a/packages/duoyun-ui/src/elements/calendar.ts
+++ b/packages/duoyun-ui/src/elements/calendar.ts
@@ -139,6 +139,10 @@ export class DuoyunCalendarElement extends GemElement {
@property highlights?: number[][];
@property renderDate?: (date: Time) => TemplateResult;
+ constructor() {
+ super({ delegatesFocus: true });
+ }
+
#isHighlight = (date: Time) => {
const t = date.valueOf();
return !!this.highlights?.some(([start, stop]) => t >= start && t <= stop);
diff --git a/packages/duoyun-ui/src/elements/card.ts b/packages/duoyun-ui/src/elements/card.ts
index ed07789d..b554c00b 100644
--- a/packages/duoyun-ui/src/elements/card.ts
+++ b/packages/duoyun-ui/src/elements/card.ts
@@ -112,7 +112,7 @@ export class DuoyunCardElement extends DuoyunLoadableBaseElement {
@attribute crossorigin: 'anonymous' | 'use-credentials';
constructor() {
- super();
+ super({ delegatesFocus: true });
this.internals.role = 'group';
}
diff --git a/packages/duoyun-ui/src/elements/carousel.ts b/packages/duoyun-ui/src/elements/carousel.ts
index fe5bcfcf..b9102943 100644
--- a/packages/duoyun-ui/src/elements/carousel.ts
+++ b/packages/duoyun-ui/src/elements/carousel.ts
@@ -176,6 +176,10 @@ export class DuoyunCarouselElement extends GemElement
{
return this.interval || 3000;
}
+ constructor() {
+ super({ delegatesFocus: true });
+ }
+
state: State = {
currentIndex: 0,
direction: 1,
diff --git a/packages/duoyun-ui/src/elements/cascader-pick.ts b/packages/duoyun-ui/src/elements/cascader-pick.ts
index 95783ff4..adb045d9 100644
--- a/packages/duoyun-ui/src/elements/cascader-pick.ts
+++ b/packages/duoyun-ui/src/elements/cascader-pick.ts
@@ -18,7 +18,7 @@ import { commonHandle } from '../lib/hotkeys';
import { focusStyle } from '../lib/styles';
import { ContextMenu } from './menu';
-import { pickerStyle } from './pick';
+import { BasePickerElement, pickerStyle } from './pick';
import type { Option, DuoyunCascaderElement } from './cascader';
import './use';
@@ -49,9 +49,9 @@ const style = createCSSSheet(css`
@adoptedStyle(style)
@adoptedStyle(pickerStyle)
@adoptedStyle(focusStyle)
-export class DuoyunCascaderPickElement extends GemElement {
+export class DuoyunCascaderPickElement extends GemElement implements BasePickerElement {
@attribute placeholder: string;
- @property options: Option[];
+ @property options?: Option[];
@boolattribute fit: boolean;
@boolattribute disabled: boolean;
@boolattribute multiple: boolean;
@@ -78,7 +78,7 @@ export class DuoyunCascaderPickElement extends GemElement {
};
#onOpen = () => {
- if (this.disabled || !this.options || !this.options.length) return;
+ if (this.disabled || !this.options?.length) return;
ContextMenu.open(
html`
`;
};
+
+ showPicker = () => this.#onOpen();
}
diff --git a/packages/duoyun-ui/src/elements/cascader.ts b/packages/duoyun-ui/src/elements/cascader.ts
index c172553a..77b0ae22 100644
--- a/packages/duoyun-ui/src/elements/cascader.ts
+++ b/packages/duoyun-ui/src/elements/cascader.ts
@@ -81,7 +81,7 @@ const token = Symbol();
export class DuoyunCascaderElement extends GemElement {
@part static column: string;
- @property options: Option[];
+ @property options?: Option[];
@boolattribute fit: boolean;
@boolattribute multiple: boolean;
@globalemitter change: Emitter<(string | number)[][] | (string | number)[]>;
@@ -158,12 +158,13 @@ export class DuoyunCascaderElement extends GemElement {
willMount = () => {
this.memo(
() => {
+ if (!this.options) return;
this.#deep = getCascaderDeep(this.options, 'children');
// init state
if (!this.state.selected.length) {
const selected: Option[] = [];
this.#value?.[0]?.forEach((val, index) => {
- const item = (index ? selected[selected.length - 1].children! : this.options).find(
+ const item = (index ? selected[selected.length - 1].children! : this.options!).find(
(e) => val === (e.value ?? e.label),
)!;
selected.push(item);
@@ -209,13 +210,14 @@ export class DuoyunCascaderElement extends GemElement {
? 1
: 0;
};
- this.options.forEach((e) => check([], e));
+ this.options?.forEach((e) => check([], e));
},
() => [this.value],
);
};
render = () => {
+ if (!this.options) return html``;
const { selected } = this.state;
const listStyle = styleMap({ width: this.fit ? `${100 / this.#deep}%` : undefined });
return html`
diff --git a/packages/duoyun-ui/src/elements/checkbox.ts b/packages/duoyun-ui/src/elements/checkbox.ts
index 62187804..2879ce7a 100644
--- a/packages/duoyun-ui/src/elements/checkbox.ts
+++ b/packages/duoyun-ui/src/elements/checkbox.ts
@@ -72,7 +72,7 @@ export class DuoyunCheckboxElement extends GemElement {
@attribute value: string;
constructor() {
- super();
+ super({ delegatesFocus: true });
this.addEventListener('click', this.#onClick);
}
@@ -112,7 +112,7 @@ export class DuoyunCheckboxGroupElement extends GemElement {
@property options?: Option[];
constructor() {
- super();
+ super({ delegatesFocus: true });
this.internals.role = 'group';
}
diff --git a/packages/duoyun-ui/src/elements/coach-mark.ts b/packages/duoyun-ui/src/elements/coach-mark.ts
index 523ab4b7..d46fc017 100644
--- a/packages/duoyun-ui/src/elements/coach-mark.ts
+++ b/packages/duoyun-ui/src/elements/coach-mark.ts
@@ -24,7 +24,7 @@ export type Tour = {
finishText?: string;
finish?: () => Promise | void;
skip?: () => Promise | void;
- maskCloseable?: boolean;
+ maskClosable?: boolean;
};
let tourList: Tour[] = [];
@@ -161,10 +161,10 @@ export class DuoyunCoachMarkElement extends DuoyunVisibleBaseElement {
#open = async () => {
if (!this.#tour) return;
- const { description, preview = '', title, finishText, maskCloseable } = this.#tour;
+ const { description, preview = '', title, finishText, maskClosable } = this.#tour;
const isFinish = store.currentIndex === tourList.length - 1;
this.scrollIntoView({ block: 'nearest', inline: 'nearest' });
- if (!this.visibility) await new Promise((res) => this.addEventListener('visible', res, { once: true }));
+ if (!this.visible) await new Promise((res) => this.addEventListener('show', res, { once: true }));
DuoyunWaitElement.instance?.remove(); // avoid inert conflict
ContextMenu.open(
html`
@@ -188,7 +188,7 @@ export class DuoyunCoachMarkElement extends DuoyunVisibleBaseElement {
`,
{
- maskCloseable,
+ maskClosable,
activeElement: this,
width: this.#width,
},
diff --git a/packages/duoyun-ui/src/elements/color-pick.ts b/packages/duoyun-ui/src/elements/color-pick.ts
index 0e31feb0..c956ef6f 100644
--- a/packages/duoyun-ui/src/elements/color-pick.ts
+++ b/packages/duoyun-ui/src/elements/color-pick.ts
@@ -6,6 +6,8 @@ import {
globalemitter,
Emitter,
boolattribute,
+ refobject,
+ RefObject,
} from '@mantou/gem/lib/decorators';
import { GemElement, html } from '@mantou/gem/lib/element';
import { createCSSSheet, css, styleMap } from '@mantou/gem/lib/utils';
@@ -15,6 +17,9 @@ import { theme } from '../lib/theme';
import { commonHandle } from '../lib/hotkeys';
import { focusStyle } from '../lib/styles';
+import type { BasePickerElement } from './pick';
+import type { DuoyunPopoverElement } from './popover';
+
import './popover';
import './color-panel';
@@ -48,16 +53,22 @@ const style = createCSSSheet(css`
@customElement('dy-color-pick')
@adoptedStyle(style)
@adoptedStyle(focusStyle)
-export class DuoyunColorPickElement extends GemElement {
+export class DuoyunColorPickElement extends GemElement implements BasePickerElement {
@attribute value: HexColor;
@boolattribute alpha: boolean;
+ @refobject popoverRef: RefObject;
@globalemitter change: Emitter;
+ constructor() {
+ super({ delegatesFocus: true });
+ }
+
render = () => {
return html`
`;
};
+
+ showPicker = () => {
+ this.popoverRef.element?.click();
+ };
}
diff --git a/packages/duoyun-ui/src/elements/compartment.ts b/packages/duoyun-ui/src/elements/compartment.ts
index f9246ceb..24b3bd24 100644
--- a/packages/duoyun-ui/src/elements/compartment.ts
+++ b/packages/duoyun-ui/src/elements/compartment.ts
@@ -14,7 +14,7 @@ const style = createCSSSheet(css`
@customElement('dy-compartment')
@adoptedStyle(style)
export class DuoyunCompartmentElement extends GemElement {
- @property content: string | number | TemplateResult;
+ @property content?: string | number | TemplateResult;
render = () => {
return html`${this.content}`;
};
diff --git a/packages/duoyun-ui/src/elements/copy.ts b/packages/duoyun-ui/src/elements/copy.ts
index b8b964cc..98528cf0 100644
--- a/packages/duoyun-ui/src/elements/copy.ts
+++ b/packages/duoyun-ui/src/elements/copy.ts
@@ -96,10 +96,6 @@ export class DuoyunCopyElement extends GemElement {
@emitter copy: Emitter;
- state: State = {
- status: 'none',
- };
-
get #icon() {
switch (this.state.status) {
case 'success':
@@ -111,6 +107,14 @@ export class DuoyunCopyElement extends GemElement {
}
}
+ constructor() {
+ super({ delegatesFocus: true });
+ }
+
+ state: State = {
+ status: 'none',
+ };
+
#showMessage = (isSuccess: boolean) => {
this.copy(isSuccess);
if (!this.silent) {
diff --git a/packages/duoyun-ui/src/elements/date-panel.ts b/packages/duoyun-ui/src/elements/date-panel.ts
index e86aceaf..c43d3bdb 100644
--- a/packages/duoyun-ui/src/elements/date-panel.ts
+++ b/packages/duoyun-ui/src/elements/date-panel.ts
@@ -155,7 +155,7 @@ export class DuoyunDatePanelElement extends GemElement {
}
constructor() {
- super();
+ super({ delegatesFocus: true });
this.internals.role = 'widget';
}
@@ -209,7 +209,7 @@ export class DuoyunDatePanelElement extends GemElement {
this.change(evt.detail);
};
- #renderCurrentPostion = () => {
+ #renderCurrentPosition = () => {
switch (this.state.mode) {
case 'day':
return html`${this.#currentPosition.formatToParts().map(({ type, value }) => {
@@ -315,7 +315,7 @@ export class DuoyunDatePanelElement extends GemElement {
@click=${() => this.#increaseView(-1)}
.element=${icons.left}
>
- ${this.#renderCurrentPostion()}
+ ${this.#renderCurrentPosition()}
{
class="timepanel"
.value=${this.value}
@change=${this.#onTimeChange}
- headerless
+ headless
>
`
diff --git a/packages/duoyun-ui/src/elements/date-pick.ts b/packages/duoyun-ui/src/elements/date-pick.ts
index 9c1118a2..774c7b75 100644
--- a/packages/duoyun-ui/src/elements/date-pick.ts
+++ b/packages/duoyun-ui/src/elements/date-pick.ts
@@ -24,7 +24,7 @@ import { focusStyle } from '../lib/styles';
import type { DuoyunButtonElement } from './button';
import type { DuoyunDatePanelElement } from './date-panel';
import { ContextMenu } from './menu';
-import { pickerStyle } from './pick';
+import { BasePickerElement, pickerStyle } from './pick';
import './use';
import './date-panel';
@@ -74,7 +74,7 @@ export interface Option {
@adoptedStyle(style)
@adoptedStyle(focusStyle)
@connectStore(icons)
-export class DuoyunDatePickElement extends GemElement {
+export class DuoyunDatePickElement extends GemElement implements BasePickerElement {
@attribute placeholder: string;
@boolattribute time: boolean;
@boolattribute clearable: boolean;
@@ -173,4 +173,6 @@ export class DuoyunDatePickElement extends GemElement {
`;
};
+
+ showPicker = () => this.#onOpen();
}
diff --git a/packages/duoyun-ui/src/elements/date-range-pick.ts b/packages/duoyun-ui/src/elements/date-range-pick.ts
index 2796a816..0b0eded5 100644
--- a/packages/duoyun-ui/src/elements/date-range-pick.ts
+++ b/packages/duoyun-ui/src/elements/date-range-pick.ts
@@ -22,7 +22,7 @@ import { focusStyle } from '../lib/styles';
import type { DuoyunButtonElement } from './button';
import { ContextMenu } from './menu';
-import { pickerStyle } from './pick';
+import { BasePickerElement, pickerStyle } from './pick';
import './use';
import './date-range-panel';
@@ -65,7 +65,7 @@ const style = createCSSSheet(css`
@adoptedStyle(style)
@adoptedStyle(pickerStyle)
@adoptedStyle(focusStyle)
-export class DuoyunDateRangePickElement extends GemElement {
+export class DuoyunDateRangePickElement extends GemElement implements BasePickerElement {
@attribute placeholder: string;
@boolattribute clearable: boolean;
@boolattribute disabled: boolean;
@@ -176,4 +176,6 @@ export class DuoyunDateRangePickElement extends GemElement {
`;
};
+
+ showPicker = () => this.#onOpen();
}
diff --git a/packages/duoyun-ui/src/elements/drop-area.ts b/packages/duoyun-ui/src/elements/drop-area.ts
index bc6e1c0c..96ee1405 100644
--- a/packages/duoyun-ui/src/elements/drop-area.ts
+++ b/packages/duoyun-ui/src/elements/drop-area.ts
@@ -60,7 +60,7 @@ export class DuoyunDropAreaElement extends GemElement {
@state allowDrop: boolean;
@globalemitter change: Emitter