1

I created a simple test app where one field is an NSTextField and another is a <textarea> instead a WKWebView. I can click into the web view once, but if I go back to the NSTextField, I'm unable to get the cursor back into the web view ever again.

Here's a demonstration:

enter image description here

As you can see, the web view is still interactive to some extent, it just can't become (I assume) the first responder again.

Is there something weird about WKWebView and the responder chain? How can I make the WebWebView behave like a normal NSTextField?

Here is a sample project built in Xcode 11.5 in case you want to try it out.

How can this be fixed?

halfer
  • 19,824
  • 17
  • 99
  • 186
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128

1 Answers1

2

The issue seems to be related to the textarea, using content editable <body contenteditable="true"></body> does seem to work.

A workaround for using the textarea is to subclass WKWebView like this:

- (void)mouseDown:(NSEvent *)event
{
    [super mouseDown:event];
    [[self window] makeFirstResponder:self];
}
catlan
  • 25,100
  • 8
  • 67
  • 78
  • Setting the `contenteditable` attribute on the `body` didn't work for me (the 2nd click on the web view is still ignored) but the `WKWebView` subclass seems to work great. Thank you! – Clifton Labrum May 30 '20 at 20:05