@amro93/ngb-select 0.2.0 → 0.3.1

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,203 @@ 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-panel-max-width` | `20rem` — the panel is at least the trigger's width and grows to its widest option up to this (and the viewport) |
319
+ | `--ngb-select-font-family` | `inherit` |
320
+ | `--ngb-select-font-size` | `inherit` |
321
+ | `--ngb-select-color` / `--ngb-select-bg` | `--bs-body-color` / `--bs-body-bg` |
322
+ | `--ngb-select-min-height-sm` | `31px` |
323
+ | `--ngb-select-min-height` (md) | `38px` |
324
+ | `--ngb-select-min-height-lg` | `48px` |
325
+ | `--ngb-select-padding-x` (`-sm`, `-lg`) | `0.75rem` (`0.5rem`, `1rem`) |
326
+ | `--ngb-select-border-color` | `--bs-border-color` |
327
+ | `--ngb-select-border-radius` | `--bs-border-radius` (`-sm`/`-lg` per size) |
328
+ | `--ngb-select-focus-border-color` | `#86b7fe` |
329
+ | `--ngb-select-focus-outline` | `0` (`--ngb-select-focus-outline-offset`) |
330
+ | `--ngb-select-focus-shadow` | `0 0 0 .25rem rgba(var(--bs-primary-rgb),.25)` |
331
+ | `--ngb-select-invalid-border-color` | `--bs-form-invalid-border-color` |
332
+ | `--ngb-select-disabled-bg` / `--ngb-select-filled-bg` | `--bs-secondary-bg` / `--bs-light` |
333
+ | `--ngb-select-icon-color` | `--bs-secondary-color` |
334
+ | `--ngb-select-accent-color` | `--bs-primary` (floating label) |
335
+ | `--ngb-select-panel-bg` | `--bs-body-bg` |
336
+ | `--ngb-select-panel-border-color` | `--bs-border-color-translucent` |
337
+ | `--ngb-select-panel-border-radius` | `--bs-border-radius` |
338
+ | `--ngb-select-panel-shadow` | `--bs-box-shadow-sm` |
339
+ | `--ngb-select-option-color` | `--bs-body-color` |
340
+ | `--ngb-select-option-padding-y` / `-x` | `0.5rem` / `1rem` |
341
+ | `--ngb-select-option-hover-bg` / `-color` | `--bs-tertiary-bg` / option color |
342
+ | `--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` |
343
+ | `--ngb-select-option-selected-bg` | `--bs-dropdown-link-active-bg` (primary) |
344
+ | `--ngb-select-option-selected-color` | `--bs-dropdown-link-active-color` (`#fff`) |
345
+ | `--ngb-select-option-selected-font-weight` | `inherit` |
346
+ | `--ngb-select-option-checked-bg` / `-color` / `-font-weight` | `--bs-light` / option color / `600` (multi-select rows) |
347
+ | `--ngb-select-check-checked-bg` | `--bs-primary` (option checkboxes) |
348
+ | `--ngb-select-chip-bg` / `-color` | `--bs-light` / `--bs-body-color` |
349
+ | `--ngb-select-chip-border-color` | `--bs-border-color` |
350
+ | `--ngb-select-chip-border-radius` / `-font-weight` | `--bs-border-radius` / `500` |
351
+
352
+ Rules use one class plus Angular's encapsulation attribute, and state modifiers are wrapped in
353
+ `:where()`, so a two-class selector (e.g. `.my-form .ngb-select-option`) is enough to override a
354
+ rule directly. Stable hooks: `.ngb-select-trigger`, `.ngb-select-panel`, `.ngb-select-option`
355
+ (`.active` single selection, `.ngb-select-option-checked` multi selection, `.focus` keyboard
356
+ focus), `.ngb-select-chip`, `.ngb-select-add-tag`.
357
+
358
+ Example — sdga-ui / DGA look:
359
+
360
+ ```scss
361
+ :root {
362
+ --ngb-select-font-family: 'IBM Plex Sans Arabic', sans-serif;
363
+ --ngb-select-color: #161616;
364
+ --ngb-select-border-color: #9da4ae;
365
+ --ngb-select-border-radius: 0.5rem;
366
+ --ngb-select-min-height-sm: 32px;
367
+ --ngb-select-min-height: 40px;
368
+ --ngb-select-min-height-lg: 48px;
369
+ --ngb-select-focus-border-color: #1b8354;
370
+ --ngb-select-focus-outline: 2px solid #1b8354;
371
+ --ngb-select-focus-outline-offset: 2px;
372
+ --ngb-select-focus-shadow: none;
373
+ --ngb-select-accent-color: #1b8354;
374
+ --ngb-select-panel-border-radius: 0.5rem;
375
+ --ngb-select-panel-shadow: 0 4px 12px rgb(16 24 40 / 0.1);
376
+ --ngb-select-option-color: #161616;
377
+ --ngb-select-option-hover-bg: #f3f4f6;
378
+ --ngb-select-option-selected-bg: #ecfdf3;
379
+ --ngb-select-option-selected-color: #161616;
380
+ --ngb-select-option-selected-font-weight: 600;
381
+ --ngb-select-option-checked-bg: #ecfdf3;
382
+ --ngb-select-check-checked-bg: #1b8354;
383
+ --ngb-select-chip-bg: #ecfdf3;
384
+ --ngb-select-chip-color: #1b8354;
385
+ --ngb-select-chip-border-color: #1b8354;
386
+ }
387
+ ```
388
+
389
+ ### Tagging (`addTag`)
390
+
391
+ With a filter (`filter` or `filterInTrigger`) and `addTag`, typing a term that matches no
392
+ option exactly (case-insensitive, Arabic-normalized) shows an **Add “term”** row after the
393
+ options. Click it, or reach it with the arrow keys and press Enter (it is pre-selected when
394
+ nothing matches): the item is created, added to the options, selected (appended in `multiple`
395
+ mode; selected and closed in single mode), the filter is cleared and `onAdd` emits.
396
+
397
+ ```html
398
+ <ngb-select
399
+ [options]="tags"
400
+ optionLabel="name"
401
+ optionValue="id"
402
+ multiple
403
+ display="chip"
404
+ filter
405
+ [addTag]="createTag"
406
+ addTagLabel="إضافة «{term}»"
407
+ (onAdd)="saveTag($event.item)"
408
+ [(ngModel)]="selectedTags"
409
+ ></ngb-select>
410
+ ```
411
+
412
+ ```ts
413
+ createTag = (term: string) => ({ id: crypto.randomUUID(), name: term }); // may return a Promise
414
+ ```
415
+
416
+ - `addTag: boolean | ((term: string) => any | Promise<any>)` — `true` creates
417
+ `{ [optionLabel]: term, [optionValue]: term }` (or the plain string for primitive options).
418
+ Returning `null`/`undefined` from the function cancels.
419
+ - `onAdd: { item, term }` — emitted after the item was selected (not emitted when
420
+ `selectionLimit` blocks it).
421
+ - Not available in `group` or `tree` mode.
422
+
223
423
  ## 📖 Documentation & Links
224
424
 
225
425
  - 🌐 **[Live Demo & Showcase](https://amro93.github.io/ngb-select/)**