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

Combobox does not fire an "on change" #3095

Open
mdurchholz opened this issue Aug 13, 2024 · 3 comments
Open

Combobox does not fire an "on change" #3095

mdurchholz opened this issue Aug 13, 2024 · 3 comments

Comments

@mdurchholz
Copy link

I am attempting to add a custom "on change" event listener to this component and am noticing that there is nothing that triggers a change event after the component is updated. I do see that the hidden select element does change, but nothing is triggering an event. Maybe I am missing something in the documentation, but is there a way to fire a callback function after the component value is updated?

@mcking65
Copy link
Contributor

@mdurchholz

Please provide the URL of the page about which you are inquiring.

@css-meeting-bot
Copy link
Member

The ARIA Authoring Practices (APG) Task Force just discussed Combobox change event question.

The full IRC log of that discussion <jugglinmike> Topic: Combobox change event question
<jugglinmike> github: https://github.com//issues/3095
<jugglinmike> Adam_Page_: If I'm understanding correctly, the reporter is using the combobox pattern, but they want an "onchange" event that they would get with a standard "select" element
<jugglinmike> Matt_King: But we would only do that if we were writing the combobox code to be reusable
<jugglinmike> Adam_Page_: Right--if, for instance, we wanted our own example to take advantage of such an event
<jugglinmike> Matt_King_: That was my gut instinct on how to respond
<jugglinmike> Zakim, end the meeting

@mdurchholz
Copy link
Author

@mcking65 - I can provide the source link: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/

There is no "on change" method for this component...

However, this being said, I think I have found a work around. In my instance, I loop through all of my select elements and am using Javascript to create the options array that this plugin needs to initialize (along with building the necessary parent HTML). From there, I am extending the "selectOption" method where I create an "on change" event listener for my hidden select element. Below is a dev URL where you can see my instances:

https://moveodev.com/delta-dental/components/styleguide/#combobox

Here is some code to show you how I have accomplished this:

var js_select = new Select(div_wrap, options);

js_select.selectOption = (function( original )
{
    return function( index )
    {
        original.call(this, index);

        el.selectedIndex = index;

        var value = el.value;

        onChange(el, index);

        var event = new CustomEvent("change", {
            bubbles: true,
            cancelable: true,
            detail: { value },
        });
    
        el.dispatchEvent(event);
    };
})(js_select.selectOption);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants