automat / controlkit.js

A lightweight controller and gui library
823 stars 82 forks source link

Specifying parentDocumentElementID prevents mouseevents from reaching the parent #30

Open sudsy opened 7 years ago

sudsy commented 7 years ago

I noticed this behaviour while implementing controlKit.

I have found a fix which involves changing:

    if (!options.parentDomElementId) {
        node = new Node();
        document.body.appendChild(node.getElement());
    } else {
        node = Node.getNodeById(options.parentDomElementId);
    }

to

    if (!options.parentDomElementId) {
        node = new Node();
        document.body.appendChild(node.getElement());
    } else {
    node = new Node();
        document.getElementById(options.parentDomElementId).appendChild(node.getElement());
    }

Ideally though, I would like it to be something more like this to allow a domElement to be passed rather than referenced by id

    var rootElement = document.body;
    if (options.parentDomElement) {
        rootElement = options.parentDomElement
    } else if(options.parentDomElementId){
        rootElement = document.getElementById(options.parentDomElementId)
    }
    node = new Node();
    rootElement.appendChild(node.getElement());

I will make these changes in my own fork and will submit a PR if you would like to merge the changes.