From 04ef9c9663fa1c57f4b55de3173f6ded47dd8a8b Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2698393+2betop@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:12:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20quickEdit=20focus?= =?UTF-8?q?=20=E9=AB=98=E4=BA=AE=E4=B8=8E=E5=88=97=E5=86=BB=E7=BB=93?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BF=AB=E9=80=9F=E7=BC=96=E8=BE=91=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E6=93=8D=E4=BD=9C=E4=BA=A4=E4=BA=92=20(#11382)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/renderers/Form.tsx | 18 ++++--- .../amis-core/src/utils/uncontrollable.tsx | 2 +- .../amis-ui/scss/components/_quick-edit.scss | 2 +- packages/amis-ui/src/components/Button.tsx | 3 ++ packages/amis-ui/src/components/Select.tsx | 13 ++--- .../__snapshots__/inputTable.test.tsx.snap | 30 ++++++++---- .../Form/__snapshots__/static.test.tsx.snap | 1 + .../__snapshots__/CRUD.test.tsx.snap | 10 ++++ packages/amis/src/renderers/Action.tsx | 6 ++- packages/amis/src/renderers/QuickEdit.tsx | 47 +++++++++++++------ 10 files changed, 92 insertions(+), 40 deletions(-) diff --git a/packages/amis-core/src/renderers/Form.tsx b/packages/amis-core/src/renderers/Form.tsx index fffd297cfba..a8900b06783 100644 --- a/packages/amis-core/src/renderers/Form.tsx +++ b/packages/amis-core/src/renderers/Form.tsx @@ -2335,13 +2335,7 @@ export class FormRendererBase extends Form { super.componentDidMount(); if (this.props.autoFocus) { - const scoped = this.context as IScopedContext; - const inputs = scoped.getComponents(); - let focuableInput = find( - inputs, - input => input.focus - ) as ScopedComponentType; - focuableInput && setTimeout(() => focuableInput.focus!(), 200); + this.focus(); } } @@ -2352,6 +2346,16 @@ export class FormRendererBase extends Form { super.componentWillUnmount(); } + focus() { + const scoped = this.context as IScopedContext; + const inputs = scoped.getComponents(); + let focuableInput = find( + inputs, + input => input.focus + ) as ScopedComponentType; + focuableInput && setTimeout(() => focuableInput.focus!(), 200); + } + doAction( action: ActionObject, data: object = this.props.store.data, diff --git a/packages/amis-core/src/utils/uncontrollable.tsx b/packages/amis-core/src/utils/uncontrollable.tsx index 82e67ae65d9..23f93fe44b6 100644 --- a/packages/amis-core/src/utils/uncontrollable.tsx +++ b/packages/amis-core/src/utils/uncontrollable.tsx @@ -6,7 +6,7 @@ export function uncontrollable< P extends { [propName: string]: any; } ->(arg: T, config: P, mapping?: any): T { +>(arg: T, config: P, mapping?: Array): T { const result = baseuncontrollable(arg, config, mapping); return hoistNonReactStatic(result, arg); } diff --git a/packages/amis-ui/scss/components/_quick-edit.scss b/packages/amis-ui/scss/components/_quick-edit.scss index 708f9197129..fe26a24f5f2 100644 --- a/packages/amis-ui/scss/components/_quick-edit.scss +++ b/packages/amis-ui/scss/components/_quick-edit.scss @@ -23,7 +23,7 @@ &:focus { position: relative; - &:after { + &:before { content: ''; left: 0; top: 0; diff --git a/packages/amis-ui/src/components/Button.tsx b/packages/amis-ui/src/components/Button.tsx index 6428b450d51..550b829a4c8 100644 --- a/packages/amis-ui/src/components/Button.tsx +++ b/packages/amis-ui/src/components/Button.tsx @@ -33,6 +33,7 @@ export interface ButtonProps classPrefix: string; classnames: ClassNamesFn; componentClass: React.ElementType; + tabIndex?: string; overrideClassName?: boolean; loading?: boolean; loadingClassName?: string; @@ -79,6 +80,7 @@ export class Button extends React.Component { overrideClassName, loadingConfig, testIdBuilder, + tabIndex, ...rest } = this.props; @@ -112,6 +114,7 @@ export class Button extends React.Component { style={style} title={title} disabled={disabled} + tabIndex={tabIndex} > {loading && !disabled && ( { } } -const EnhancedSelect = themeable( - localeable( - uncontrollable(Select, { - value: 'onChange' - }) - ) +const methods = ['focus', 'blur']; +const EnhancedSelect = uncontrollable( + themeable(localeable(Select, methods), methods), + { + value: 'onChange' + }, + methods ); export default EnhancedSelect; diff --git a/packages/amis/__tests__/renderers/Form/__snapshots__/inputTable.test.tsx.snap b/packages/amis/__tests__/renderers/Form/__snapshots__/inputTable.test.tsx.snap index 32bac504bd2..424bcae90e5 100644 --- a/packages/amis/__tests__/renderers/Form/__snapshots__/inputTable.test.tsx.snap +++ b/packages/amis/__tests__/renderers/Form/__snapshots__/inputTable.test.tsx.snap @@ -438,7 +438,8 @@ exports[`Renderer:input table add 1`] = ` data-index="0" >