mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(editor): Do not focus expression input if it was not in focus before switching (#18744)
This commit is contained in:
@@ -4,7 +4,7 @@ import type { useNDVStore } from '@/stores/ndv.store';
|
|||||||
import type { CompletionResult } from '@codemirror/autocomplete';
|
import type { CompletionResult } from '@codemirror/autocomplete';
|
||||||
import { createTestingPinia } from '@pinia/testing';
|
import { createTestingPinia } from '@pinia/testing';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
import { waitFor } from '@testing-library/vue';
|
import { waitFor, within } from '@testing-library/vue';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import type { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
import type { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||||
import { useSettingsStore } from '@/stores/settings.store';
|
import { useSettingsStore } from '@/stores/settings.store';
|
||||||
@@ -556,4 +556,51 @@ describe('ParameterInput.vue', () => {
|
|||||||
eventBus.emit('optionSelected', 'removeExpression');
|
eventBus.emit('optionSelected', 'removeExpression');
|
||||||
expect(emitted('update')).toContainEqual([expect.objectContaining({ value: '{{ }}' })]);
|
expect(emitted('update')).toContainEqual([expect.objectContaining({ value: '{{ }}' })]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should maintain focus after changing to expression', async () => {
|
||||||
|
const { rerender, getByRole, getByTestId } = renderComponent({
|
||||||
|
props: {
|
||||||
|
path: 'name',
|
||||||
|
parameter: {
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
modelValue: 'test',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const input = getByRole('textbox');
|
||||||
|
expect(input).toBeInTheDocument();
|
||||||
|
await userEvent.click(input);
|
||||||
|
await rerender({ modelValue: '={{ $json.foo }}' });
|
||||||
|
|
||||||
|
const expressionEditor = getByTestId('inline-expression-editor-input');
|
||||||
|
expect(expressionEditor).toBeInTheDocument();
|
||||||
|
const expressionEditorInput = within(expressionEditor).getByRole('textbox');
|
||||||
|
await waitFor(() => expect(expressionEditorInput).toHaveFocus());
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when not in focus', () => {
|
||||||
|
test('should not focus after changing to expression ', async () => {
|
||||||
|
const { rerender, getByRole, getByTestId } = renderComponent({
|
||||||
|
props: {
|
||||||
|
path: 'name',
|
||||||
|
parameter: {
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
modelValue: 'test',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const input = getByRole('textbox');
|
||||||
|
expect(input).toBeInTheDocument();
|
||||||
|
await rerender({ modelValue: '={{ $json.foo }}' });
|
||||||
|
|
||||||
|
const expressionEditor = getByTestId('inline-expression-editor-input');
|
||||||
|
expect(expressionEditor).toBeInTheDocument();
|
||||||
|
const expressionEditorInput = within(expressionEditor).getByRole('textbox');
|
||||||
|
await waitFor(() => expect(expressionEditorInput).not.toHaveFocus());
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1150,7 +1150,7 @@ watch(remoteParameterOptionsLoading, () => {
|
|||||||
|
|
||||||
// Focus input field when changing between fixed and expression
|
// Focus input field when changing between fixed and expression
|
||||||
watch(isModelValueExpression, async (isExpression, wasExpression) => {
|
watch(isModelValueExpression, async (isExpression, wasExpression) => {
|
||||||
if (!props.isReadOnly && isExpression !== wasExpression) {
|
if (!props.isReadOnly && isFocused.value && isExpression !== wasExpression) {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
await setFocus();
|
await setFocus();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user