@amro93/ngb-select 0.1.7 → 0.3.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 CHANGED
@@ -20,6 +20,9 @@ A comprehensive, lightweight Angular Standalone select component that utilizes *
20
20
  - ♿ **Accessible** - ARIA roles implemented (`combobox`, `listbox`, `option`) alongside keyboard navigation.
21
21
  - ⚡ **Editable Combobox** - Allows custom user typing directly into the select input.
22
22
  - 🎯 **Focus on Open** - Programmatically scroll and focus a specific option index when the popup opens.
23
+ - 🌍 **i18n & RTL** - Every built-in text is an input, settable app-wide with `provideNgbSelectConfig`; logical CSS mirrors the layout under `dir="rtl"`.
24
+ - 🎨 **Themeable** - `--ngb-select-*` CSS custom properties, no `!important`.
25
+ - 🏷️ **Tagging** - `addTag` creates options from the filter text.
23
26
 
24
27
  ---
25
28
 
@@ -220,6 +223,202 @@ Override default rendering for options and the selected value using `<ng-templat
220
223
 
221
224
  ---
222
225
 
226
+ ## 🌍 Labels, i18n, RTL, Theming & Tagging
227
+
228
+ ### Labels & accessibility (`inputId`)
229
+
230
+ The trigger is a focusable `div[role="combobox"]`. Give it an id with `inputId` and point a
231
+ `<label for>` at it: clicking the label focuses the select (it never opens it or "clicks" an
232
+ option), and the trigger gets `aria-labelledby` = the label's id (an id is assigned to the label
233
+ if it has none). A `<label>` wrapping the select works the same way.
234
+
235
+ ```html
236
+ <label for="city" class="dga-label required">المدينة</label>
237
+ <ngb-select inputId="city" [options]="cities" formControlName="city"></ngb-select>
238
+ ```
239
+
240
+ - `inputId` goes on the trigger only; the host element never carries the same id. The older
241
+ `id` input still works (it is moved to the trigger and removed from the host).
242
+ - Naming precedence: `ariaLabelledBy` → `ariaLabel` (disables the automatic label lookup) →
243
+ the associated `<label>`.
244
+ - Option rows are rendered only while the panel is open, so a closed select has no option
245
+ buttons that a surrounding `<label>` could activate.
246
+
247
+ ### Localization (i18n) of built-in texts
248
+
249
+ Every built-in string has an input, defaulting to English. Set them once for the whole app with
250
+ `provideNgbSelectConfig`; a per-instance input still wins.
251
+
252
+ ```ts
253
+ import { provideNgbSelectConfig } from '@amro93/ngb-select';
254
+
255
+ bootstrapApplication(AppComponent, {
256
+ providers: [
257
+ provideNgbSelectConfig({
258
+ labels: {
259
+ clear: 'مسح',
260
+ clearValue: 'مسح القيمة',
261
+ loading: 'جارٍ التحميل...',
262
+ selectAll: 'تحديد الكل',
263
+ done: 'تم',
264
+ close: 'إغلاق',
265
+ expand: 'توسيع',
266
+ collapse: 'طي',
267
+ removeChip: 'إزالة {label}',
268
+ addTag: 'إضافة «{term}»',
269
+ emptyMessage: 'لا توجد نتائج',
270
+ emptyFilterMessage: 'لا توجد نتائج مطابقة',
271
+ searchPlaceholder: 'بحث...',
272
+ popupTitle: 'اختر',
273
+ selectedItems: '{0} عناصر محددة',
274
+ },
275
+ }),
276
+ ],
277
+ });
278
+ ```
279
+
280
+ | Input | Config key | Default (English) | Used for |
281
+ | -------------------- | -------------------- | ---------------------- | ----------------------------------------- |
282
+ | `clearLabel` | `clear` | `'Clear'` | `title` of the clear icon |
283
+ | `clearValueLabel` | `clearValue` | `'Clear value'` | `aria-label` of the clear icon |
284
+ | `loadingLabel` | `loading` | `'Loading...'` | screen-reader text of the spinner |
285
+ | `selectAllLabel` | `selectAll` | `'Select All'` | "Select All" checkbox label |
286
+ | `doneLabel` | `done` | `'Done'` | modal footer button |
287
+ | `closeLabel` | `close` | `'Close'` | `aria-label` of the modal close button |
288
+ | `expandLabel` | `expand` | `'Expand'` | `aria-label` of a collapsed tree toggle |
289
+ | `collapseLabel` | `collapse` | `'Collapse'` | `aria-label` of an expanded tree toggle |
290
+ | `removeChipLabel` | `removeChip` | `'Remove {label}'` | `aria-label`/`title` of a chip's remove × |
291
+ | `addTagLabel` | `addTag` | `'Add “{term}”'` | tagging row (`{term}` or `{0}`) |
292
+ | `emptyMessage` | `emptyMessage` | `'No results found'` | no options |
293
+ | `emptyFilterMessage` | `emptyFilterMessage` | `'No results found'` | filter matched nothing |
294
+ | `searchPlaceholder` | `searchPlaceholder` | `'Search...'` | fallback placeholder of the search input |
295
+ | `popupTitle` | `popupTitle` | `'Select an Option'` | fallback modal title |
296
+ | `selectedItemsLabel` | `selectedItems` | `'{0} items selected'` | summary above `maxSelectedLabels` |
297
+
298
+ ### RTL
299
+
300
+ Under `dir="rtl"` (on the page or any ancestor, or via the `dir` input) the component mirrors
301
+ with logical CSS only (`margin-inline-*`, `inset-inline-*`): search icon, chips and their ×,
302
+ clear and chevron icons all flip. With `appendTo="body"` the panel is positioned with inline
303
+ `!important` `left`/`right`/`top` styles aligned to the trigger's inline-start edge (its right
304
+ edge in RTL), so design-system rules such as
305
+ `[dir=rtl] .dropdown-menu { inset-inline-start: 0 !important }` cannot pin it to the viewport
306
+ edge. The panel carries its own `ngb-select-panel` class (plus `.dropdown-menu` for the
307
+ Bootstrap look) and a `dir` attribute copied from the select.
308
+
309
+ ### Theming with CSS custom properties
310
+
311
+ All visual values come from `--ngb-select-*` custom properties (with Bootstrap fallbacks). The
312
+ component never declares them and uses no `!important`, so set them anywhere with plain
313
+ selectors. Use `:root` (or a wrapper of `<body>`) when you use `appendTo="body"`, because the
314
+ panel then leaves the `ngb-select` subtree.
315
+
316
+ | Property | Default |
317
+ | ---------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
318
+ | `--ngb-select-font-family` | `inherit` |
319
+ | `--ngb-select-font-size` | `inherit` |
320
+ | `--ngb-select-color` / `--ngb-select-bg` | `--bs-body-color` / `--bs-body-bg` |
321
+ | `--ngb-select-min-height-sm` | `31px` |
322
+ | `--ngb-select-min-height` (md) | `38px` |
323
+ | `--ngb-select-min-height-lg` | `48px` |
324
+ | `--ngb-select-padding-x` (`-sm`, `-lg`) | `0.75rem` (`0.5rem`, `1rem`) |
325
+ | `--ngb-select-border-color` | `--bs-border-color` |
326
+ | `--ngb-select-border-radius` | `--bs-border-radius` (`-sm`/`-lg` per size) |
327
+ | `--ngb-select-focus-border-color` | `#86b7fe` |
328
+ | `--ngb-select-focus-outline` | `0` (`--ngb-select-focus-outline-offset`) |
329
+ | `--ngb-select-focus-shadow` | `0 0 0 .25rem rgba(var(--bs-primary-rgb),.25)` |
330
+ | `--ngb-select-invalid-border-color` | `--bs-form-invalid-border-color` |
331
+ | `--ngb-select-disabled-bg` / `--ngb-select-filled-bg` | `--bs-secondary-bg` / `--bs-light` |
332
+ | `--ngb-select-icon-color` | `--bs-secondary-color` |
333
+ | `--ngb-select-accent-color` | `--bs-primary` (floating label) |
334
+ | `--ngb-select-panel-bg` | `--bs-body-bg` |
335
+ | `--ngb-select-panel-border-color` | `--bs-border-color-translucent` |
336
+ | `--ngb-select-panel-border-radius` | `--bs-border-radius` |
337
+ | `--ngb-select-panel-shadow` | `--bs-box-shadow-sm` |
338
+ | `--ngb-select-option-color` | `--bs-body-color` |
339
+ | `--ngb-select-option-padding-y` / `-x` | `0.5rem` / `1rem` |
340
+ | `--ngb-select-option-hover-bg` / `-color` | `--bs-tertiary-bg` / option color |
341
+ | `--ngb-select-option-pressed-bg` / `--ngb-select-option-pressed-color` | Option while the mouse is pressed (defaults to the hover values); wins over a design system's `.dropdown-item:active` |
342
+ | `--ngb-select-option-selected-bg` | `--bs-dropdown-link-active-bg` (primary) |
343
+ | `--ngb-select-option-selected-color` | `--bs-dropdown-link-active-color` (`#fff`) |
344
+ | `--ngb-select-option-selected-font-weight` | `inherit` |
345
+ | `--ngb-select-option-checked-bg` / `-color` / `-font-weight` | `--bs-light` / option color / `600` (multi-select rows) |
346
+ | `--ngb-select-check-checked-bg` | `--bs-primary` (option checkboxes) |
347
+ | `--ngb-select-chip-bg` / `-color` | `--bs-light` / `--bs-body-color` |
348
+ | `--ngb-select-chip-border-color` | `--bs-border-color` |
349
+ | `--ngb-select-chip-border-radius` / `-font-weight` | `--bs-border-radius` / `500` |
350
+
351
+ Rules use one class plus Angular's encapsulation attribute, and state modifiers are wrapped in
352
+ `:where()`, so a two-class selector (e.g. `.my-form .ngb-select-option`) is enough to override a
353
+ rule directly. Stable hooks: `.ngb-select-trigger`, `.ngb-select-panel`, `.ngb-select-option`
354
+ (`.active` single selection, `.ngb-select-option-checked` multi selection, `.focus` keyboard
355
+ focus), `.ngb-select-chip`, `.ngb-select-add-tag`.
356
+
357
+ Example — sdga-ui / DGA look:
358
+
359
+ ```scss
360
+ :root {
361
+ --ngb-select-font-family: 'IBM Plex Sans Arabic', sans-serif;
362
+ --ngb-select-color: #161616;
363
+ --ngb-select-border-color: #9da4ae;
364
+ --ngb-select-border-radius: 0.5rem;
365
+ --ngb-select-min-height-sm: 32px;
366
+ --ngb-select-min-height: 40px;
367
+ --ngb-select-min-height-lg: 48px;
368
+ --ngb-select-focus-border-color: #1b8354;
369
+ --ngb-select-focus-outline: 2px solid #1b8354;
370
+ --ngb-select-focus-outline-offset: 2px;
371
+ --ngb-select-focus-shadow: none;
372
+ --ngb-select-accent-color: #1b8354;
373
+ --ngb-select-panel-border-radius: 0.5rem;
374
+ --ngb-select-panel-shadow: 0 4px 12px rgb(16 24 40 / 0.1);
375
+ --ngb-select-option-color: #161616;
376
+ --ngb-select-option-hover-bg: #f3f4f6;
377
+ --ngb-select-option-selected-bg: #ecfdf3;
378
+ --ngb-select-option-selected-color: #161616;
379
+ --ngb-select-option-selected-font-weight: 600;
380
+ --ngb-select-option-checked-bg: #ecfdf3;
381
+ --ngb-select-check-checked-bg: #1b8354;
382
+ --ngb-select-chip-bg: #ecfdf3;
383
+ --ngb-select-chip-color: #1b8354;
384
+ --ngb-select-chip-border-color: #1b8354;
385
+ }
386
+ ```
387
+
388
+ ### Tagging (`addTag`)
389
+
390
+ With a filter (`filter` or `filterInTrigger`) and `addTag`, typing a term that matches no
391
+ option exactly (case-insensitive, Arabic-normalized) shows an **Add “term”** row after the
392
+ options. Click it, or reach it with the arrow keys and press Enter (it is pre-selected when
393
+ nothing matches): the item is created, added to the options, selected (appended in `multiple`
394
+ mode; selected and closed in single mode), the filter is cleared and `onAdd` emits.
395
+
396
+ ```html
397
+ <ngb-select
398
+ [options]="tags"
399
+ optionLabel="name"
400
+ optionValue="id"
401
+ multiple
402
+ display="chip"
403
+ filter
404
+ [addTag]="createTag"
405
+ addTagLabel="إضافة «{term}»"
406
+ (onAdd)="saveTag($event.item)"
407
+ [(ngModel)]="selectedTags"
408
+ ></ngb-select>
409
+ ```
410
+
411
+ ```ts
412
+ createTag = (term: string) => ({ id: crypto.randomUUID(), name: term }); // may return a Promise
413
+ ```
414
+
415
+ - `addTag: boolean | ((term: string) => any | Promise<any>)` — `true` creates
416
+ `{ [optionLabel]: term, [optionValue]: term }` (or the plain string for primitive options).
417
+ Returning `null`/`undefined` from the function cancels.
418
+ - `onAdd: { item, term }` — emitted after the item was selected (not emitted when
419
+ `selectionLimit` blocks it).
420
+ - Not available in `group` or `tree` mode.
421
+
223
422
  ## 📖 Documentation & Links
224
423
 
225
424
  - 🌐 **[Live Demo & Showcase](https://amro93.github.io/ngb-select/)**