swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.24k stars 744 forks source link

Support Radio Input Label `for` Attribute #667

Open onet4 opened 5 years ago

onet4 commented 5 years ago

Nice plugin.

When I create a menu with radio inputs, clicking on the radio label text does not check the radio button for the first time. Multiple clicks seem to be required.

My suggestion is to give those radio buttons the temporary id attribute and set the for attribute to the label tag with the value of the radio id.

I did this with the show callback but the menu started moving jittery. So it should be better built-in.

events: {
    show: function(opt) {
        var $this = this;   
        opt.$menu.find( 'input[type=radio]' ).each( function( index, value ){
            var _id = 'context-menu-radio-' + index;
            $( this ).attr( 'id', _id );
            $( this ).parent().attr( 'for', _id ); // label tag misses the for attribute
        } );
...
bbrala commented 5 years ago

Seems an reasonable idea. Thanks.