FR: Settings: Pass MouseEvent to ExtraButtonComponent.onClick()

Hi,

I’d like to request the following new feature to the API.

I’d like to detect if the Ctrl/Cmd key was pressed when an extra button was clicked in settings. This can be done, if there’s access to a MouseEvent object, because MouseEvent.ctrlKey tells it (at least for Ctrl, I’m not sure about Mac’s Cmd key, because I don’t have a Mac).

If I’d use a ButtonComponent instead of an ExtraButtonComponent, I could access the MouseEvent object. However, ButtonComponent is bigger and therefore does not suit my settings layout, where I want to have small icon buttons. ExtraButtonComponent is perfect for the layout.

Here’s a simplified example code describing the difference between ExtraButtonComponent and ButtonComponent:

new Setting(container_element)
    .addExtraButton(extra_button => extra_button
        .onClick((/* Callback has no parameters*/) => {
            // ...
        }),
    )
    .addButton(normal_button => normal_button
        .onClick((mouse_event: MouseEvent) => {
            // ...
        }),
    )
;

Obsidian API 0.14.8 does not introduce the MouseEvent argument for the callback used in ExtraButton.Component.onClick().

A workaround

new Setting(container_element)
    .addExtraButton(extra_button => extra_button
        .extraSettingsEl.addEventListener("click", (mouse_event: MouseEvent) => {
            if (mouse_event.ctrlKey) {
                // ...
            }
        }),
    )
;

This works, but is not as intuitive, and perhaps it can break if Obsidian API changes later?

Thank you for considering this! :sunglasses: