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

[feature request] tabs: html elements in title #594

Open
eviltik opened this issue Dec 26, 2023 · 2 comments
Open

[feature request] tabs: html elements in title #594

eviltik opened this issue Dec 26, 2023 · 2 comments

Comments

@eviltik
Copy link

eviltik commented Dec 26, 2023

Hi !

Currently, addTab only support title attribute, which is pushed into the Dom as innerText (i think), not innerHTML. So we can't put our title in a span or use google material symbols icons without a little hack.

image

Hack:

  installTabs() {

    // let's add an "icon" attribute
    const pages = [
      { title:'General', icon:'page_info', },
      { title:'Layers', icon:'layers' },
      { title:'Lights', icon:'lightbulb' },
      { title:'Config', icon:'settings_applications' }
    ];

    // this.gui is an instance of tweakpane
    this.tabs = this.gui.addTab({ pages } );

    this.tabGeneral = this.tabs.pages[0];
    this.tabLayers = this.tabs.pages[1];
    this.tabLights = this.tabs.pages[2];
    this.tabConfig = this.tabs.pages[3];

    // update tab title with icons if needed
    let i = 0;
    document.querySelectorAll('.tp-tbiv_t').forEach(el => {
      if (pages[i].icon) {
        el.innerHTML = `<i class="msy-sharp" title="${el.innerText}">${pages[i].icon}</i>`;
      }
      i++;
    });
  }

It should be great to be able to set HTML directly in pages elements, i.e

const pages = [
  { html:'<i class="msy-sharp" title="General">page_info</i>' },
  { html:'<i class="msy-sharp" title="Layers">layers</i>' },
  { html:'<i class="msy-sharp" title="Lights">lightbulb</i>' },
  { html:'<i class="msy-sharp" title="Config">settings_applications</i>' }
];

this.tabs = this.gui.addTab({ pages } );

What do you think ?

I was using DAT.gui, then lil-gui, now definitively switched to tweakpane. Great job !

@eviltik eviltik changed the title html in tabs title tabs: html elements in title Dec 26, 2023
@eviltik eviltik changed the title tabs: html elements in title [feature request] tabs: html elements in title Dec 26, 2023
@cocopon
Copy link
Owner

cocopon commented Dec 26, 2023

Thank you for using Tweakpane!

Using innerHTML should be avoided due to its potential security risks. What do you think about adding a new property icon: HTMLElement instead?

@eviltik
Copy link
Author

eviltik commented Dec 27, 2023

The security risk is minor because tabs title are defined by the developer. But tabs title (or icons) can come from a database or outside too, who know's ... so ...

Agree with an icon:HTMLElement implementation !

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

No branches or pull requests

2 participants