svelteuidev / svelteui

SvelteUI Monorepo
https://svelteui.dev
MIT License
1.27k stars 63 forks source link

Allow `null` as `Tooltip.opened` #421

Closed notramo closed 1 year ago

notramo commented 1 year ago

What package has an issue

@svelteuidev/core Tooltip component

Description

When passing null as <Tooltip opened={null}> (or omitting it), it's in automatic mode, when passing bool, it's in managed mode. Hovever, it's useful to be able to conditionally switch between automatic and managed mode (e.g. on first visit, the tooltip is permanently shown in managed mode, then switch to automatic).

<script>
  let firstVisit = true;
</script>
<Tooltip
  opened={firstVisit || null}
  label="Click this button, nothing happens."
>
  <Button on:click={() => firstVisit = false}>{ firstVisit ? 'Got it!' : 'No action'}</Button>
</Tooltip>

The above behavior works, but the TS type checker complains about null value, also it's undocumented.

BeeMargarida commented 1 year ago

I think you get the same behaviour by setting the value to undefined, which should raise any TS type issues. I've added better mention of this behaviour in the docs, thank you!