Skip to content

Commit

Permalink
[duoyun-ui] Fixed <dy-keyboard-access>
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Jan 19, 2024
1 parent 8ec8fd9 commit 823b2a1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
7 changes: 3 additions & 4 deletions packages/duoyun-ui/src/elements/color-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { commonHandle } from '../lib/hotkeys';
import { focusStyle } from '../lib/styles';

import type { BasePickerElement } from './picker';
import type { DuoyunPopoverElement } from './popover';

import './popover';
import './color-panel';
Expand Down Expand Up @@ -64,7 +63,7 @@ const style = createCSSSheet(css`
export class DuoyunColorPickerElement extends GemElement implements BasePickerElement {
@attribute value: HexColor;
@boolattribute alpha: boolean;
@refobject popoverRef: RefObject<DuoyunPopoverElement>;
@refobject divRef: RefObject<HTMLDivElement>;
@boolattribute disabled: boolean;

@globalemitter change: Emitter<HexColor>;
Expand All @@ -77,7 +76,6 @@ export class DuoyunColorPickerElement extends GemElement implements BasePickerEl
return html`
<dy-popover
trigger="click"
ref=${this.popoverRef.ref}
.disabled=${this.disabled}
.content=${html`
<dy-color-panel
Expand All @@ -90,6 +88,7 @@ export class DuoyunColorPickerElement extends GemElement implements BasePickerEl
>
<div
role="combobox"
ref=${this.divRef.ref}
tabindex=${-Number(this.disabled)}
aria-disabled=${this.disabled}
@keydown=${commonHandle}
Expand All @@ -101,6 +100,6 @@ export class DuoyunColorPickerElement extends GemElement implements BasePickerEl
};

showPicker() {
this.popoverRef.element?.click();
this.divRef.element?.click();
}
}
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/file-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class DuoyunFilePickerElement extends GemElement implements BasePickerEle
const renderItem = this.#type === 'file' ? this.#renderFileItem : this.#renderImageItem;

return html`
<input
<input
hidden
type="file"
?multiple=${this.multiple}
Expand Down
12 changes: 10 additions & 2 deletions packages/duoyun-ui/src/elements/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,25 @@ export class DuoyunInputElement extends GemElement {
this.#inputHandle();
};

#onClear = (evt: Event) => {
#onClear = async (evt: Event) => {
evt.stopPropagation();
this.clear('');
this.focus();
this.#history.save();
// click handle 之后会聚焦到 target 上
await Promise.resolve();
this.focus();
};

#history = new InputHistory(this);

#onKeyDown = (evt: KeyboardEvent) => {
const nextValue = (n: number) => String(clamp(this.#min, Number(this.value || this.min) + n, this.#max));
hotkeys({
esc: () => {
// Chrome: 当在 search 输入框上 esc 时,会触发输入为 '' 的事件
// 这里组织默认处理
},
})(evt);
if (this.type === 'number') {
hotkeys(
{
Expand Down
9 changes: 3 additions & 6 deletions packages/duoyun-ui/src/elements/keyboard-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,9 @@ export class DuoyunKeyboardAccessElement extends GemElement<State> {
// `a-b`
keydownHandles[[...key].join('-')] = () => {
this.setState({ active: false });
if ('showPicker' in element) {
(element as HTMLInputElement).showPicker();
} else {
element.focus();
element.click();
}
// BasePickerElement 的 `showPicker` 一样支持通过 `click` 触发
element.focus();
element.click();
};
index++;
return { key, top, left };
Expand Down
2 changes: 1 addition & 1 deletion packages/duoyun-ui/src/elements/shortcut-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class DuoyunShortcutRecordElement extends GemElement {

#onClear = () => {
this.clear(null);
this.focus();
// 由于 target 不能聚集,所以会自动聚焦到 this
};

render = () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/duoyun-ui/src/patterns/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { DuoyunButtonElement } from '../elements/button';
import { locale } from '../lib/locale';
import { icons } from '../lib/icons';
import { isNotBoolean } from '../lib/types';
import { hotkeys } from '../lib/hotkeys';

import { locationStore } from './console';
import type { FilterableOptions, FilterableType } from './filter-form';
Expand Down Expand Up @@ -289,6 +290,15 @@ export class DyPatTableElement<T = any> extends GemElement<State> {
evt.stopPropagation();
};

#onKeydown = (evt: KeyboardEvent) => {
hotkeys({
esc: () => {
this.setState({ search: '' });
this.#changeQueryThrottle();
},
})(evt);
};

#onAddFilter = (data: Filter) => {
ContextMenu.close();
this.setState({ filters: [...this.state.filters, data] });
Expand Down Expand Up @@ -435,6 +445,7 @@ export class DyPatTableElement<T = any> extends GemElement<State> {
clearable
@clear=${this.#onSearch}
@change=${this.#onSearch}
@keydown=${this.#onKeydown}
.value=${this.state.search}
></dy-input>
${this.filterable
Expand Down

0 comments on commit 823b2a1

Please sign in to comment.