I'm currently working on detecting when a text input field is active. Initially, I used the onfocus
event, but I encountered an issue where the onblur
event would be triggered when the window was no longer in focus, causing unintended consequences in my application. While there's the DOMActivate
event that gets fired, Firefox doesn't trigger it for text:input
fields.
In a document, only one element can be active at a time. An active element may not necessarily have focus, but an element with focus is always the active element within the document. For instance, if an active element in a window that isn't the foreground window loses its focus, it's no longer considered active.
Fires: button, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:reset, input:submit
Does not fire: input:text, select, textarea
I also tried using the input
event, but this event is only triggered when actual typing occurs in the input box. In my case, I need to capture when the text input field becomes active before any input is typed in and ensure it remains active even when the window is not in focus.
I believe a possible solution could involve using a mutation observer to check if the mutated element becomes the activeElement
, but this approach seems like it would require additional overhead. Also, since there isn't an event for scenarios where the active element is lost, it might require extra tracking. Is there a more direct or efficient method to achieve this?
This task involves a Firefox add-on built using addon SDK.