Fixed a bug where escape would delete all typed content (#30452)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3af8d50bbe
Коммит
e2a7240e34
@@ -14,7 +14,7 @@ import type Textbox from 'components/textbox/textbox';
|
|||||||
|
|
||||||
import mergeObjects from 'packages/mattermost-redux/test/merge_objects';
|
import mergeObjects from 'packages/mattermost-redux/test/merge_objects';
|
||||||
import {renderWithContext, userEvent, screen} from 'tests/react_testing_utils';
|
import {renderWithContext, userEvent, screen} from 'tests/react_testing_utils';
|
||||||
import {Locations, StoragePrefixes} from 'utils/constants';
|
import Constants, {Locations, StoragePrefixes} from 'utils/constants';
|
||||||
import {TestHelper} from 'utils/test_helper';
|
import {TestHelper} from 'utils/test_helper';
|
||||||
|
|
||||||
import type {PostDraft} from 'types/store/draft';
|
import type {PostDraft} from 'types/store/draft';
|
||||||
@@ -202,6 +202,37 @@ describe('components/avanced_text_editor/advanced_text_editor', () => {
|
|||||||
const textbox = screen.getByTestId('post_textbox');
|
const textbox = screen.getByTestId('post_textbox');
|
||||||
userEvent.type(textbox, 'something{esc}');
|
userEvent.type(textbox, 'something{esc}');
|
||||||
expect(textbox).not.toHaveFocus();
|
expect(textbox).not.toHaveFocus();
|
||||||
|
expect(mockedUpdateDraft).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ESC should blur the input and reset draft when in editing mode', () => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
const props = {
|
||||||
|
...baseProps,
|
||||||
|
isInEditMode: true,
|
||||||
|
};
|
||||||
|
renderWithContext(
|
||||||
|
<AdvancedTextEditor
|
||||||
|
{...props}
|
||||||
|
/>,
|
||||||
|
mergeObjects(initialState, {
|
||||||
|
entities: {
|
||||||
|
roles: {
|
||||||
|
roles: {
|
||||||
|
user_roles: {permissions: [Permissions.CREATE_POST]},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const textbox = screen.getByTestId('edit_textbox');
|
||||||
|
userEvent.type(textbox, 'something{esc}');
|
||||||
|
expect(textbox).not.toHaveFocus();
|
||||||
|
|
||||||
|
// save is called with a short delayed after pressing escape key
|
||||||
|
jest.advanceTimersByTime(Constants.SAVE_DRAFT_TIMEOUT + 50);
|
||||||
|
expect(mockedRemoveDraft).toHaveBeenCalled();
|
||||||
|
expect(mockedUpdateDraft).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -173,9 +173,9 @@ const useKeyHandler = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyPressed(e, KeyCodes.ESCAPE)) {
|
if (Keyboard.isKeyPressed(e, KeyCodes.ESCAPE)) {
|
||||||
onCancel?.();
|
|
||||||
textboxRef.current?.blur();
|
textboxRef.current?.blur();
|
||||||
if (isInEditMode) {
|
if (isInEditMode) {
|
||||||
|
onCancel?.();
|
||||||
dispatch(unsetEditingPost());
|
dispatch(unsetEditingPost());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user