Skip to content

Commit

Permalink
feat: data-placeholder attribute for Select.Value (#284)
Browse files Browse the repository at this point in the history
* feat: placeholder data attr

* update docs

* add changeset
  • Loading branch information
huntabyte authored Jan 18, 2024
1 parent 07b4333 commit f0d80f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/quick-pandas-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": minor
---

feat: adds `data-placeholder` attribute to `Select.Value` when no value is selected / when the placeholder is being displayed
5 changes: 5 additions & 0 deletions src/content/api-reference/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ export const value: APISchema = {
{
name: "select-value",
description: "Present on the value element."
},
{
name: "placeholder",
description:
"Present when the placeholder is being displayed (there isn't a value selected). You can use this to style the placeholder differently than the selected value."
}
]
};
Expand Down
7 changes: 6 additions & 1 deletion src/lib/bits/select/components/select-value.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
{#if asChild}
<slot {label} {attrs} />
{:else}
<span bind:this={el} {...$$restProps} {...attrs}>
<span
bind:this={el}
{...$$restProps}
{...attrs}
data-placeholder={!label ? "" : undefined}
>
{label ? label : placeholder}
</span>
{/if}

0 comments on commit f0d80f6

Please sign in to comment.