import '../../../../globals.js';
// Copyright 2022-2024, University of Colorado Boulder
/**
 * A Node represented by a heading in the parallel dom that can receive focus. Typically
 * headings are not focusable and not interactive. But it may be desirable to put focus
 * on a heading to orient the user or control where the traversal order starts without
 * focusing an interactive component.
 *
 * When a screen reader is focused on a heading it will read the name of the heading and
 * possibly the content below it.
 *
 * @author Jesse Greenberg (PhET Interactive Simulations)
 */
import optionize from '../../../../phet-core/js/optionize.js';
import { Node, scenery } from '../../imports.js';
class FocusableHeadingNode extends Node {
    constructor(providedOptions) {
        const options = optionize()({
            headingLevel: 1
        }, providedOptions);
        super(options);
        this.tagName = `h${options.headingLevel}`;
        // This Node is focusable but there is no interactive component to surround with a highlight.
        this.focusHighlight = 'invisible';
        // After losing focus, this element is removed from the traversal order. It can only receive
        // focus again after calling focus() directly.
        const blurListener = {
            blur: () => { this.focusable = false; }
        };
        this.addInputListener(blurListener);
        this.disposeFocusableHeadingNode = () => {
            this.removeInputListener(blurListener);
        };
    }
    /**
     * Focus this heading in the Parallel DOM. The screen reader will read its name and possibly
     * content below it. Traversal with alternative input will continue from wherever this element
     * is located in the PDOM order.
     *
     * Once the heading loses focus, it is removed from the traversal order until this is called
     * explicitly again.
     */
    focus() {
        this.focusable = true;
        super.focus();
    }
    dispose() {
        this.disposeFocusableHeadingNode();
        super.dispose();
    }
}
scenery.register('FocusableHeadingNode', FocusableHeadingNode);
export default FocusableHeadingNode;
//# sourceMappingURL=FocusableHeadingNode.js.map