mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 09:51:36 +00:00
feat(combo-box): add hideLabel
prop (#2153)
This commit is contained in:
parent
7754ea3691
commit
436dea47e8
7 changed files with 50 additions and 1 deletions
|
@ -671,6 +671,7 @@ export interface ComboBoxItem {
|
|||
| size | No | <code>let</code> | No | <code>"sm" | "xl"</code> | <code>undefined</code> | Set the size of the combobox |
|
||||
| disabled | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the combobox |
|
||||
| titleText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the title text of the combobox |
|
||||
| hideLabel | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text |
|
||||
| placeholder | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the placeholder text |
|
||||
| helperText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the helper text |
|
||||
| invalidText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the invalid state text |
|
||||
|
|
|
@ -1851,6 +1851,18 @@
|
|||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "hideLabel",
|
||||
"kind": "let",
|
||||
"description": "Set to `true` to visually hide the label text",
|
||||
"type": "boolean",
|
||||
"value": "false",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "placeholder",
|
||||
"kind": "let",
|
||||
|
|
|
@ -24,6 +24,15 @@ Override the default slot to customize the display of each item. Access the item
|
|||
|
||||
<FileSource src="/framed/ComboBox/ComboBoxSlot" />
|
||||
|
||||
## Hidden label
|
||||
|
||||
<ComboBox hideLabel titleText="Hidden Label" placeholder="Select contact method"
|
||||
items={[
|
||||
{id: "0", text: "Slack"},
|
||||
{id: "1", text: "Email"},
|
||||
{id: "2", text: "Fax"}
|
||||
]} />
|
||||
|
||||
## Initial selected id
|
||||
|
||||
<ComboBox titleText="Contact" placeholder="Select contact method"
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
/** Specify the title text of the combobox */
|
||||
export let titleText = "";
|
||||
|
||||
/** Set to `true` to visually hide the label text */
|
||||
export let hideLabel = false;
|
||||
|
||||
/** Specify the placeholder text */
|
||||
export let placeholder = "";
|
||||
|
||||
|
@ -226,7 +229,12 @@
|
|||
|
||||
<div class:bx--list-box__wrapper={true}>
|
||||
{#if titleText || $$slots.titleText}
|
||||
<label for={id} class:bx--label={true} class:bx--label--disabled={disabled}>
|
||||
<label
|
||||
for={id}
|
||||
class:bx--label={true}
|
||||
class:bx--label--disabled={disabled}
|
||||
class:bx--visually-hidden={hideLabel}
|
||||
>
|
||||
<slot name="titleText">
|
||||
{titleText}
|
||||
</slot>
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
export let invalidText = "";
|
||||
export let warnText = "";
|
||||
export let helperText = "";
|
||||
export let hideLabel = false;
|
||||
export let size: "sm" | "xl" | undefined = undefined;
|
||||
export let shouldFilterItem: ComponentProps<ComboBox>["shouldFilterItem"] = (
|
||||
item,
|
||||
|
@ -31,6 +32,7 @@
|
|||
<ComboBox
|
||||
{disabled}
|
||||
{helperText}
|
||||
{hideLabel}
|
||||
{invalid}
|
||||
{invalidText}
|
||||
{items}
|
||||
|
|
|
@ -96,6 +96,17 @@ describe("ComboBox", () => {
|
|||
expect(screen.getByText("Contact")).toHaveClass("bx--label--disabled");
|
||||
});
|
||||
|
||||
it("should handle hidden label", () => {
|
||||
render(ComboBox, {
|
||||
props: {
|
||||
titleText: "Hidden Label",
|
||||
hideLabel: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(screen.getByText("Hidden Label")).toHaveClass("bx--visually-hidden");
|
||||
});
|
||||
|
||||
it("should handle invalid state", () => {
|
||||
render(ComboBox, {
|
||||
props: {
|
||||
|
|
6
types/ComboBox/ComboBox.svelte.d.ts
vendored
6
types/ComboBox/ComboBox.svelte.d.ts
vendored
|
@ -60,6 +60,12 @@ type $Props = {
|
|||
*/
|
||||
titleText?: string;
|
||||
|
||||
/**
|
||||
* Set to `true` to visually hide the label text
|
||||
* @default false
|
||||
*/
|
||||
hideLabel?: boolean;
|
||||
|
||||
/**
|
||||
* Specify the placeholder text
|
||||
* @default ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue