🐛 Fixed slash not working in Koenig link editor (#19198)

fixes ADM-43 https://github.com/TryGhost/Product/issues/4213

- The slash '/' search was firing when it wasn't suppose to, eg via the
URL editor inside the minimal koenig editors.
- this fix makes sure that if any input field has focus, that the slash
search function doesn't get fired.
This commit is contained in:
Ronald Langeveld 2023-11-30 12:16:05 +02:00 committed by GitHub
parent c07218dff4
commit 6983699e1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,11 @@ const Sidebar: React.FC = () => {
// Focus in on search field when pressing "/"
useEffect(() => {
const handleKeyPress = (e: KeyboardEvent) => {
// ensures it doesn't fire when typing in a text field, particularly useful for the Koenig Editor.
if (e.target instanceof HTMLElement &&
(e.target.nodeName === 'INPUT' || e.target.nodeName === 'TEXTAREA' || e.target.isContentEditable)) {
return;
}
if (e.key === '/' && !isAnyTextFieldFocused) {
e?.preventDefault();
if (searchInputRef.current) {