@rcarls/rc-search-bar 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -0
- package/dist/custom-elements.json +672 -0
- package/dist/demo.css +85 -0
- package/dist/demo.js +40 -0
- package/dist/rc-search-bar-Ssb7YNqn.js +313 -0
- package/dist/rc-search-bar-Ssb7YNqn.js.map +1 -0
- package/dist/rc-search-bar-define.js +6 -0
- package/dist/rc-search-bar-define.js.map +1 -0
- package/dist/rc-search-bar.js +5 -0
- package/dist/rc-search-bar.js.map +1 -0
- package/dist/types/packages/rc-search-bar/src/define.d.ts +1 -0
- package/dist/types/packages/rc-search-bar/src/index.d.ts +1 -0
- package/dist/types/packages/rc-search-bar/src/rc-search-bar.d.ts +123 -0
- package/dist/types/packages/rc-search-bar/src/rc-search-bar.styles.d.ts +2 -0
- package/dist/types/packages/rc-search-bar/src/rc-search-bar.test.d.ts +0 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# `@rcarls/rc-search-bar`
|
|
2
|
+
|
|
3
|
+
Enhances a consumer-provided native `<input type="search">` with leading icon
|
|
4
|
+
chrome, an accessible clear button, and debounced search events.
|
|
5
|
+
|
|
6
|
+
The native input is **required** and stays in light DOM as the source of
|
|
7
|
+
truth: form submission (`name`), label association (`label[for]`, wrapping
|
|
8
|
+
`<label>`, `aria-label`), and pre-upgrade usability all keep working. Without
|
|
9
|
+
a slotted search input the component renders no chrome and stays inert.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @rcarls/rc-search-bar
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Import
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// Registers <rc-search-bar>
|
|
23
|
+
import '@rcarls/rc-search-bar/define';
|
|
24
|
+
|
|
25
|
+
// Or import the class without registering
|
|
26
|
+
import { RCSearchBar } from '@rcarls/rc-search-bar';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Basic usage
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
<search>
|
|
35
|
+
<label for="q" class="visually-hidden">Search recipes</label>
|
|
36
|
+
<rc-search-bar placeholder="Search 51 recipes">
|
|
37
|
+
<span slot="leading" aria-hidden="true">🔍</span>
|
|
38
|
+
<input type="search" id="q" name="q" />
|
|
39
|
+
</rc-search-bar>
|
|
40
|
+
</search>
|
|
41
|
+
|
|
42
|
+
<script>
|
|
43
|
+
document.querySelector('rc-search-bar').addEventListener(
|
|
44
|
+
'rc-search-bar-input',
|
|
45
|
+
(e) => console.log(e.detail.value),
|
|
46
|
+
);
|
|
47
|
+
</script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The component's shadow CSS already strips the slotted input's native border,
|
|
51
|
+
background, and outline so it blends into the wrapper chrome — no consumer reset
|
|
52
|
+
needed.
|
|
53
|
+
|
|
54
|
+
The native WebKit cancel button is suppressed automatically. Set
|
|
55
|
+
`allow-native-clear` to restore it.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Controlled and uncontrolled value
|
|
60
|
+
|
|
61
|
+
- **Uncontrolled** — the input (and the user) own the value. Optionally seed
|
|
62
|
+
it with `default-value`; an author `value` attribute on the input wins over
|
|
63
|
+
`default-value`.
|
|
64
|
+
- **Controlled** — assign the `value` property. Host writes are silent (no
|
|
65
|
+
events) and win over slotted author values, including across re-slots.
|
|
66
|
+
User interaction always dispatches events.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### Properties / attributes
|
|
73
|
+
|
|
74
|
+
| Property | Attribute | Type | Default | Description |
|
|
75
|
+
|---|---|---|---|---|
|
|
76
|
+
| `value` | — | `string` | `''` | Current search value; reads from the native input, host writes are silent |
|
|
77
|
+
| `defaultValue` | `default-value` | `string \| undefined` | `undefined` | Initial uncontrolled value hint, applied once |
|
|
78
|
+
| `debounce` | `debounce` | `number` | `200` | Debounce window in ms for `rc-search-bar-input`; `0` dispatches synchronously |
|
|
79
|
+
| `clearLabel` | `clear-label` | `string` | `'Clear search'` | Accessible label for the clear button |
|
|
80
|
+
| `allowNativeClear` | `allow-native-clear` | `boolean` | `false` | When set, restores the browser's native WebKit cancel button |
|
|
81
|
+
| `showClearOnFocus` | `show-clear-on-focus` | `boolean` | `false` | When set, shows the clear button on focus even with no value (Apple HIG cancel pattern) |
|
|
82
|
+
| `placeholder` | `placeholder` | `string \| undefined` | `undefined` | Mirrored onto the input unless the author already set one |
|
|
83
|
+
|
|
84
|
+
### CSS custom properties
|
|
85
|
+
|
|
86
|
+
| Property | Default | Description |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `--rc-search-bar-bg` | `Field` | Wrapper background |
|
|
89
|
+
| `--rc-search-bar-color` | `FieldText` | Wrapper text color |
|
|
90
|
+
| `--rc-search-bar-icon-color` | `GrayText` | Leading icon color |
|
|
91
|
+
| `--rc-search-bar-clear-color` | `GrayText` | Clear button glyph color |
|
|
92
|
+
| `--rc-search-bar-radius` | `var(--rc-control-radius, 0)` | Wrapper border radius |
|
|
93
|
+
| `--rc-search-bar-height` | `48px` | Wrapper block size |
|
|
94
|
+
| `--rc-search-bar-padding-inline` | `0.5em` | Wrapper horizontal padding |
|
|
95
|
+
| `--rc-search-bar-gap` | `0.25em` | Gap between icon, input, and clear button |
|
|
96
|
+
|
|
97
|
+
### CSS parts
|
|
98
|
+
|
|
99
|
+
| Part | Element | Description |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `root` | wrapper `div` | The field chrome |
|
|
102
|
+
| `leading` | `span` | Wrapper around the leading icon slot |
|
|
103
|
+
| `clear` | `button` | The clear button |
|
|
104
|
+
|
|
105
|
+
### Slots
|
|
106
|
+
|
|
107
|
+
| Slot | Description |
|
|
108
|
+
|---|---|
|
|
109
|
+
| *(default)* | The required native `<input type="search">` |
|
|
110
|
+
| `leading` | Decorative leading icon; mark it `aria-hidden="true"` |
|
|
111
|
+
| `clear-icon` | Optional glyph replacing the default ✕ in the clear button |
|
|
112
|
+
| `trailing` | Optional content after the clear button (supplementary badges or actions) |
|
|
113
|
+
|
|
114
|
+
### Events
|
|
115
|
+
|
|
116
|
+
| Event | Detail | Description |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `rc-search-bar-input` | `{ value: string }` | Debounced after typing; fired immediately (pending timer cancelled) on clear |
|
|
119
|
+
| `rc-search-bar-clear` | `{}` | Fired when the clear button is activated |
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Accessibility notes
|
|
124
|
+
|
|
125
|
+
- The component writes no ARIA to the input — `type="search"` already exposes
|
|
126
|
+
the `searchbox` role, and author labels are never overwritten. Label the
|
|
127
|
+
input with `label[for]`, a wrapping `<label>`, or `aria-label`.
|
|
128
|
+
- The component adds no `role="search"` landmark; wrap in `<search>` or
|
|
129
|
+
`<form role="search">` when the bar is the page's search landmark.
|
|
130
|
+
- The clear button is a real `<button>` with a configurable `aria-label`
|
|
131
|
+
(`clear-label`) and a ≥24×24 px hit target. Activating it returns focus to
|
|
132
|
+
the input before the button hides, so focus is never dropped.
|
|
133
|
+
- The native WebKit cancel button is suppressed automatically via an adopted
|
|
134
|
+
document stylesheet. Set `allow-native-clear` to restore it. When restored,
|
|
135
|
+
it clears through the normal input path (a debounced `rc-search-bar-input`
|
|
136
|
+
with an empty value) and never fires `rc-search-bar-clear`.
|
|
137
|
+
- Set `show-clear-on-focus` to show the clear button whenever the input is
|
|
138
|
+
focused (Apple HIG cancel pattern). Consider `clear-label="Cancel"` in this
|
|
139
|
+
mode. The `rc-search-bar-clear` event fires even when the value is empty,
|
|
140
|
+
allowing the host to dismiss a search overlay.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Browser support
|
|
145
|
+
|
|
146
|
+
Evergreen browsers. The component is inert without JavaScript: the native
|
|
147
|
+
search input remains fully usable and form-associated before upgrade.
|