前提・実現したいこと
厳密にはcontenteditable
が効かないわけではなく、「フォーカスが合わない」という問題が発生しています。
今、下記のようなSVGを描画させるhtmlファイルがあります。
normal.html
html:normal.html
1<!DOCTYPE html> 2<html lang="en" dir="ltr"> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <div> 9 <svg style="border: 1px solid rgba(0, 0, 0, 0.4);" class="injected-svg" xml:space="preserve" enable-background="new 0 0 533 1071.6" viewBox="0 0 533 1071.6" y="0px" x="0px" id="Top" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"> 10 <g xmlns="http://www.w3.org/2000/svg" id="Background"> 11 <rect fill="#FFFFFF" width="533" height="1071.6"></rect> 12 </g> 13 <g xmlns="http://www.w3.org/2000/svg" id="Name"> 14 <foreignObject xmlns="" x="0" y="897.6101000000001" width="533" height="100" font-size="48" font-family="NotoSansCJKjp-Regular"> 15 <div xmlns="http://www.w3.org/1999/xhtml" style="text-align: center;"> 16 <span xmlns="http://www.w3.org/1999/xhtml" contenteditable="true">Name</span> 17 </div> 18 </foreignObject> 19 </g> 20 <g xmlns="http://www.w3.org/2000/svg" id="Message"> 21 <foreignObject xmlns="" x="0" y="0" width="533" height="336.7" font-size="64" font-family="NotoSansCJKjp-Regular"> 22 <div xmlns="http://www.w3.org/1999/xhtml" style="width: 533px; height: 336.7px; display: flex; flex-direction: column; justify-content: center; text-align: center; line-height: 1.1;"> 23 <span xmlns="http://www.w3.org/1999/xhtml" contenteditable="true">Message</span> 24 </div> 25 </foreignObject> 26 </g> 27 </svg> 28 </div> 29 </body> 30</html> 31
<span>
にcontenteditable
属性を持たせ、テキスト編集できるようにしました。
svg
1<span xmlns="http://www.w3.org/1999/xhtml" contenteditable="true">Message</span>
normal.html
の方は何も問題なく<span>
で囲まれたテキストをクリックし、フォーカスを当て、テキストを編集することができます。
しかし、下記(big.html
)のようにサイズをものすごく大きくしたSVGを表示した場合、<span>
で囲まれたテキストをクリックしてもフォーカスが合いません(テキスト部分をクリックしてもキャレットが表示されません)。
id=Name
内の<span>
の場合、「N」の横周辺をクリックするとなんとかフォーカスがあってくれることがあります。
big.html
html:big.html
1<!DOCTYPE html> 2<html lang="en" dir="ltr"> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <div> 9 <svg style="border: 1px solid rgba(0, 0, 0, 0.4);" class="injected-svg" xml:space="preserve" enable-background="new 0 0 4989 10431.5" viewBox="0 0 4989 10431.5" y="0px" x="0px" id="Top" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"> 10 <g xmlns="http://www.w3.org/2000/svg" id="Background"> 11 <rect x="56.7" y="141.7" fill="#FFFFFF" width="4875.6" height="10148"></rect> 12 </g> 13 <g xmlns="http://www.w3.org/2000/svg" id="Name"> 14 <foreignObject xmlns="" x="0" y="7849" width="4989" height="100" font-size="500" font-family="NotoSansCJKjp-Regular"> 15 <div xmlns="http://www.w3.org/1999/xhtml" style="text-align: center;"> 16 <span xmlns="http://www.w3.org/1999/xhtml" contenteditable="true">Name</span> 17 </div> 18 </foreignObject> 19 </g> 20 <g xmlns="http://www.w3.org/2000/svg" id="Message"> 21 <foreignObject xmlns="" x="0" y="141.7" width="4989" height="2915.3" font-size="700" font-family="NotoSansCJKjp-Regular"> 22 <div xmlns="http://www.w3.org/1999/xhtml" style="width: 4989px; height: 2915.3px; display: flex; flex-direction: column; justify-content: center; text-align: center; line-height: 1.1;"> 23 <span xmlns="http://www.w3.org/1999/xhtml" contenteditable="true">Message</span> 24 </div> 25 </foreignObject> 26 </g> 27 </svg> 28 </div> 29 </body> 30</html> 31
normal.html
のようにテキストのどこをクリックしてもフォーカスが合い、テキストを編集できるようにしたいのですが、
原因は何なのでしょうか?
また、どうすれば解決できるのでしょうか?
何かご回答を頂けると助かります<(_ _)>
追記
Firefoxでbig.html
を表示して試してみたところ、<span>
内のテキストをクリックしたところ、テキスト編集がてきました。しかし、id=Name
の部分はなぜかテキストの表示すらされませんでした。
ホントに原因がわからない...
追記2
あなたの回答
tips
プレビュー