Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContextMenuCloseWatcher #10809

Open
Zhang-Junzhi opened this issue Nov 30, 2024 · 1 comment
Open

ContextMenuCloseWatcher #10809

Zhang-Junzhi opened this issue Nov 30, 2024 · 1 comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@Zhang-Junzhi
Copy link

Zhang-Junzhi commented Nov 30, 2024

Problem

Due to the fact that the closing operation of the context menu may differ from ordinary close requests (for example, in the Linux Chrome browser, a pointerdown event outside of the context menu can trigger the context menu to close, while ordinary close events are triggered by click events). Therefore, using CloseWatcher class to simulate the context menu would result in the simulated context menu's closing conditions being inconsistent with those of the standard context menu. Such user experience is not ideal.

The absence of information regarding "whether the focus should return to the target element" is also one of the reasons why CloseWatcher is insufficient(See details below).

Solution

Therefore, I propose the addition of a ContextMenuCloseWatcher class, which is similar to CloseWatcher. Below is a simple code demonstration:

<menu id="ctxmenu" role="menu" tabindex="-1">...</menu>
ele.addEventListener("contextmenu", evt =>
{
    evt.preventDefault()

    let watcher = new ContextMenuCloseWatcher()
    watcher.onclose = shouldReturnFocus =>
    {
        //Close ctxmenu
        //...

        shouldReturnFocus && ele.focus()
    }

    //Show ctxmenu
    //...

    ctxmenu.focus()
})

ContextMenuCloseWatcher also differs from CloseWatcher in one aspect:

There is no parameter for the close event callback of CloseWatcher, while there is one parameter for that of ContextMenuCloseWatcher: shouldReturnFocus. If the closing of the context menu is usually accompanied by a change of focus in the document (for example, if the mouse clicks elsewhere), then shouldReturnFocus is false; if the change implies that the focus should be returned to the very target element of the context menu (for example, the user presses ESC), then shouldReturnFocus is true.

The behavior of creating ContextMenuCloseWatcher on platforms that do not support context menus is left for further discussion.

@Zhang-Junzhi Zhang-Junzhi added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Nov 30, 2024
@smaug----
Copy link

FWIW, All the event handler callbacks have a parameter, the event object. (Well, error and beforeunload event handlers may have a bit more complicated parameters, but that setup is a legacy thing and shouldn't be used in new APIs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

2 participants