Annotation dialog is not getting autofocus
When using the annotation tool, the annotation name dialog pops up but the input field is not automatically focused as expected and described in the dialog element HTML spec, specifically in the part about the dialog focusing step.
Steps to reproduce:
- Open some file in the viewer
- Select the annotation tool
- Drag and drop over the image
- Notice that the dialog appears, but the input field doesn't receive the focus (sometimes it receives in the first time that the dialog is open, but not on the next)
Initial investigation
This is not an issue in the annotation tool, as it works on the cornerstoneTools example (ie, the input gets focus whenever the dialog is open, even without setting the autofocus attribute in the input element - per the spec mentioned).
On the viewer, even if we add a $inputInsideDialog.focus(), it does not get the focus - it seems to lose it "instantaneously". It does work if I call $inputInsideDialog.focus() within a timeout of 0 though.
Digging deeper, it seems to be related to the sendActivationTrigger events on the imageViewerViewport.js, as that callback makes the active viewport "steal" the focus upon every call (which happens for all cornerstoneTools events) - relevant code here.
I traced the inclusion of the $element.focus(); back to 220ff065dc238bbcab44edfab5430cbf4af9f288 (which is related to the Lesion Tracker) but I'm unsure of the impact of changing it. In my scenario, which is the use of the StandaloneViewer, I moved that little block (which sets the focus) to be after the check of the viewport index (if (viewportIndex === activeViewportIndex) return;) and it worked - the dialog could have its focus properly and I didn't see any errors with the other tools.
I have tried the fix proposed by changing the $element.focus(); place inside imageViewerViewport.js
Tested a lot of scenarios and seems to be working fine.
I have created a PR in order to fix it. https://github.com/OHIF/Viewers/pull/265