vrimar / construct-ui

A Mithril.js UI library
https://vrimar.github.io/construct-ui
MIT License
287 stars 24 forks source link

Tooltips must be built in same closure they are used? #11

Closed angrytongan closed 4 years ago

angrytongan commented 4 years ago

Having some trouble understanding how tooltips are bound. The example below uses 4 tooltips on 4 icons, but only 3 tooltips are shown. Probably my misunderstanding of how the elements are related to siblings / parents at creation time. Any help would be greatly appreciated.

const {
    Icon,
    Tooltip,
} = CUI;

const prebuiltTooltip = m(Tooltip, {
    content: 'prebuilt broken tooltip',
    trigger: m(Icon, {
        name: 'frown',
    }),
});

const functionBuiltTooltip = () => {
    return m(Tooltip, {
        content: 'function built non-broken tooltip',
        trigger: m(Icon, {
            name: 'smile',
        })
    });
};

const TooltipTesting = {
    view: () => {
        const closureBuiltTooltip = m(Tooltip, {
            content: 'closure-built non-broken tooltip',
            trigger: m(Icon, {
                name: 'smile',
            }),
        });

        return m('', [
            prebuiltTooltip,
            functionBuiltTooltip(),
            closureBuiltTooltip,
            m(Tooltip, {
                content: 'non-broken tooltip',
                trigger: m(Icon, {
                    name: 'smile',
                }),
            }),
        ]);
    }
};

document.addEventListener('DOMContentLoaded', () => {
    m.route(document.body, '/', {
        '/': TooltipTesting
    });
});
angrytongan commented 4 years ago

Not a bug - I've demonstrated a mithril Component anti-pattern.