From 240b2bf162bcdf55f3f27d96d82c5fcc74bbcd55 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Fri, 23 Dec 2022 12:12:40 +0200
Subject: [PATCH] alt autoFocus

---
 editors/demo/src/HHMI/config/config.js                    | 1 +
 wax-prosemirror-services/src/ImageService/AltComponent.js | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js
index 70ca2465e..162052fd5 100644
--- a/editors/demo/src/HHMI/config/config.js
+++ b/editors/demo/src/HHMI/config/config.js
@@ -63,6 +63,7 @@ export default {
 
   SchemaService: DefaultSchema,
   RulesService: [emDash, ellipsis],
+  ImageService: { showAlt: true },
 
   PmPlugins: [columnResizing(), tableEditing(), invisibles([hardBreak()])],
   services: [
diff --git a/wax-prosemirror-services/src/ImageService/AltComponent.js b/wax-prosemirror-services/src/ImageService/AltComponent.js
index 9786988c1..35ab8914b 100644
--- a/wax-prosemirror-services/src/ImageService/AltComponent.js
+++ b/wax-prosemirror-services/src/ImageService/AltComponent.js
@@ -1,3 +1,4 @@
+/* eslint-disable react/prop-types */
 import React, { useContext, useLayoutEffect, useRef, useState } from 'react';
 import styled from 'styled-components';
 import { WaxContext } from 'wax-prosemirror-core';
@@ -65,10 +66,14 @@ export default ({ setPosition, position }) => {
 
   const imageConfig = app.config.get('config.ImageService');
   const showAlt = imageConfig && imageConfig.showAlt;
+  const autoFocus =
+    activeView.state.selection &&
+    activeView.state.selection.node &&
+    activeView.state.selection.node.attrs.alt === '';
 
   return !readOnly && showAlt ? (
     <StyledInputAlt
-      autoFocus="autoFocus"
+      autoFocus={autoFocus}
       key="alt"
       onChange={altTextOnChange}
       placeholder="Alt Text"
-- 
GitLab