Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Added

- Added `hoverContent` prop to `six-tab` to override the default hover content.
- Added `CheckboxMultiSelectValueAccessor` on Angular which binds checkbox values to an array analog
to a multiselect

## 5.1.0 - 2025-10-23

Expand Down
8 changes: 8 additions & 0 deletions examples/angular/src/app/form/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ <h2>Form Example</h2>
</six-layout-grid>
</six-group-label>

<six-group-label class="column-span-6 checkbox-group" label="Privileges">
<six-layout-grid columns="1">
<six-checkbox value="read" six-checkbox-group [formControl]="form.controls.privileges">read</six-checkbox>
<six-checkbox value="write" six-checkbox-group [formControl]="form.controls.privileges">write</six-checkbox>
<six-checkbox value="delete" six-checkbox-group [formControl]="form.controls.privileges">delete</six-checkbox>
</six-layout-grid>
</six-group-label>

<six-textarea class="column-span-6" label="Description" [formControl]="form.controls.description" />
<six-checkbox class="column-span-6" [formControl]="form.controls.acceptsTerms"
>Accept to Terms and Condition</six-checkbox
Expand Down
2 changes: 2 additions & 0 deletions examples/angular/src/app/form/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Form {
iban: ['', Validators.pattern(/[A-Z]{2}\d{2}[A-Z ]+/)],
age: [null as number | null, Validators.min(18)],
userGroup: ['user' as UserGroup, Validators.required],
privileges: [['read'] as Privilege[]],
status: ['enabled' as Status | null, Validators.required],
internal: [false, Validators.requiredTrue],
date: [null as string | null, [Validators.required]],
Expand Down Expand Up @@ -63,3 +64,4 @@ function usernameValidator(control: AbstractControl): ValidationErrors | null {
type UserGroup = 'admin' | 'developer' | 'user';
type Status = 'enabled' | 'disabled' | 'temporary';
type Interest = 'sport' | 'music' | 'movies';
type Privilege = 'read' | 'write' | 'delete';
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Directive, ElementRef, HostListener, Injector, Input } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from './value-accessor';

@Directive({
selector: '[six-checkbox-group]',
standalone: false,
})
export class SixCheckboxGroupDirective {}

// Accessor applies only when the SixCheckboxGroupDirective attribute is present
@Directive({
selector: 'six-checkbox[six-checkbox-group]',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: CheckboxMultiSelectValueAccessor,
multi: true,
},
],
standalone: false,
})
export class CheckboxMultiSelectValueAccessor<T extends string = string> extends ValueAccessor {
@Input({ required: true }) value!: T;

constructor(injector: Injector, el: ElementRef) {
super(injector, el);
}

@HostListener('change', ['$event.target'])
onHostChange(el: HTMLSixCheckboxElement) {
const checked = el.checked;
const current = this.ngControl?.value;
if (!current) return;

const set = new Set<T>(current);
checked ? set.add(this.value) : set.delete(this.value);

this.handleValueChange(el, Array.from(set));
}

override writeValue(values: T[]): void {
const arr = Array.isArray(values) ? (values as T[]) : [];
const checkbox = this.el.nativeElement as HTMLSixCheckboxElement;
checkbox.checked = arr.includes(this.value);
this.updateValidation();
}

override setDisabledState(isDisabled: boolean): void {
this.el.nativeElement.disabled = isDisabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from './value-accessor';

@Directive({
selector: 'six-checkbox',
selector: 'six-checkbox:not([six-checkbox-group])',
providers: [
{
provide: NG_VALUE_ACCESSOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UI_LIBRARY_CONFIG, UiLibraryConfig } from '../ui-library-angular-config
@Directive()
export class ValueAccessor implements ControlValueAccessor, AfterViewInit, OnDestroy {
private statusChanges?: Subscription;
private ngControl?: NgControl;
public ngControl?: NgControl;
private initialErrorText?: string;
private validationMessagesService = inject(ValidationMessagesService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
} from './validators/six-ui-library-validators';
import { SelectValueAccessor } from './control-value-accessors/select-value-accessor';
import { CheckboxValueAccessor } from './control-value-accessors/checkbox-value-accessor';
import {
CheckboxMultiSelectValueAccessor,
SixCheckboxGroupDirective,
} from './control-value-accessors/checkbox-multi-select-value-accessor';
import { RangeValueAccessor } from './control-value-accessors/range-value-accessor';
import { SwitchValueAccessor } from './control-value-accessors/switch-value-accessor';
import { TimepickerValueAccessor } from './control-value-accessors/timepicker-value-accessor';
Expand Down Expand Up @@ -45,6 +49,8 @@ import { DEFAULT_UI_LIBRARY_CONFIG, UI_LIBRARY_CONFIG, UiLibraryConfig } from '.
TimepickerValueAccessor,
SelectValueAccessor,
CheckboxValueAccessor,
CheckboxMultiSelectValueAccessor,
SixCheckboxGroupDirective,
SwitchValueAccessor,
RangeValueAccessor,

Expand Down Expand Up @@ -84,6 +90,8 @@ import { DEFAULT_UI_LIBRARY_CONFIG, UI_LIBRARY_CONFIG, UiLibraryConfig } from '.
TimepickerValueAccessor,
SelectValueAccessor,
CheckboxValueAccessor,
CheckboxMultiSelectValueAccessor,
SixCheckboxGroupDirective,
SwitchValueAccessor,
RangeValueAccessor,

Expand Down
1 change: 1 addition & 0 deletions libraries/ui-library-angular/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './lib/control-value-accessors/date-value-accessor';
export * from './lib/control-value-accessors/timepicker-value-accessor';
export * from './lib/control-value-accessors/select-value-accessor';
export * from './lib/control-value-accessors/checkbox-value-accessor';
export * from './lib/control-value-accessors/checkbox-multi-select-value-accessor';
export * from './lib/control-value-accessors/switch-value-accessor';
export * from './lib/control-value-accessors/range-value-accessor';

Expand Down