obsidianmd/obsidian-api

Bug: `setDisabled()` does not affect ColorComponent UI

AstroMash opened this issue · 2 comments

Steps to reproduce:

  • Create a setting for a ColorComponent and call setDisabled(true)
    new Setting(containerEl)
      .addColorPicker((setting) => {
        setting.setValue('#7D5AED');
    }).setDisabled(true);
  • Open Settings UI and verify the issue
    • Color picker input element is not disabled
    • The settingEl will have is-disabled appended
    • A new color can be selected, but it will not persist
    • There is no visual indication that the setting will not be saved

I've worked around this in the callback of setDisabled:

setting.setDisabled(shouldDisable).then((setting) => {
  if (shouldDisable) {
    setting.settingEl.style.opacity = '0.5';
    setting.controlEl.getElementsByTagName('input')[0].disabled = true;
    setting.controlEl.getElementsByTagName('input')[0].style.cursor = 'not-allowed';
    setting.controlEl.getElementsByTagName('input')[0].title = 'Other setting must be enabled to use this setting.';
  } else {
    setting.settingEl.style.opacity = '1';
    setting.controlEl.getElementsByTagName('input')[0].disabled = false;
    setting.controlEl.getElementsByTagName('input')[0].style.cursor = 'pointer';
    setting.controlEl.getElementsByTagName('input')[0].title = '';
  }
});

Just thought you guys should know if you aren't already aware. Apologies if you are, I couldn't find anything while searching.

Will be fixed in a future release.

Wonderful! Thank you 👊