feat(toolbar-search): add disabled state

This commit is contained in:
Eric Liu 2021-02-03 16:19:17 -08:00
commit edc361d392
4 changed files with 25 additions and 3 deletions

View file

@ -4151,6 +4151,7 @@ None.
| expanded | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to expand the search bar | | expanded | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to expand the search bar |
| value | <code>let</code> | Yes | <code>number &#124; string</code> | <code>""</code> | Specify the value of the search input | | value | <code>let</code> | Yes | <code>number &#124; string</code> | <code>""</code> | Specify the value of the search input |
| persistent | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to keep the search bar expanded | | persistent | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to keep the search bar expanded |
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the search bar |
| tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex | | tabindex | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify the tabindex |
### Slots ### Slots

View file

@ -3069,6 +3069,16 @@
"constant": false, "constant": false,
"reactive": false "reactive": false
}, },
{
"name": "disabled",
"kind": "let",
"description": "Set to `true` to disable the search bar",
"type": "boolean",
"value": "false",
"isFunction": false,
"constant": false,
"reactive": false
},
{ {
"name": "tabindex", "name": "tabindex",
"kind": "let", "kind": "let",

View file

@ -11,6 +11,9 @@
/** Set to `true` to keep the search bar expanded */ /** Set to `true` to keep the search bar expanded */
export let persistent = false; export let persistent = false;
/** Set to `true` to disable the search bar */
export let disabled = false;
/** Specify the tabindex */ /** Specify the tabindex */
export let tabindex = "0"; export let tabindex = "0";
@ -21,10 +24,10 @@
export let ref = null; export let ref = null;
import { tick } from "svelte"; import { tick } from "svelte";
import { Search } from "../Search"; import Search from "../Search/Search.svelte";
async function expandSearch() { async function expandSearch() {
if (persistent || expanded) return; if (disabled || persistent || expanded) return;
expanded = true; expanded = true;
await tick(); await tick();
ref.focus(); ref.focus();
@ -32,17 +35,19 @@
</script> </script>
<div <div
tabindex="{expanded ? '-1' : tabindex}" tabindex="{expanded || disabled ? '-1' : tabindex}"
class:bx--toolbar-action="{true}" class:bx--toolbar-action="{true}"
class:bx--toolbar-search-container-active="{expanded}" class:bx--toolbar-search-container-active="{expanded}"
class:bx--toolbar-search-container-expandable="{!persistent}" class:bx--toolbar-search-container-expandable="{!persistent}"
class:bx--toolbar-search-container-persistent="{persistent}" class:bx--toolbar-search-container-persistent="{persistent}"
class:bx--toolbar-search-container-disabled="{disabled}"
on:click="{expandSearch}" on:click="{expandSearch}"
on:focus="{expandSearch}" on:focus="{expandSearch}"
> >
<Search <Search
size="sm" size="sm"
tabindex="{expanded ? tabindex : '-1'}" tabindex="{expanded ? tabindex : '-1'}"
disabled="{disabled}"
{...$$restProps} {...$$restProps}
bind:ref bind:ref
bind:value bind:value

View file

@ -19,6 +19,12 @@ export interface ToolbarSearchProps {
*/ */
persistent?: boolean; persistent?: boolean;
/**
* Set to `true` to disable the search bar
* @default false
*/
disabled?: boolean;
/** /**
* Specify the tabindex * Specify the tabindex
* @default "0" * @default "0"