diff --git a/apps/radix-docs/src/api-doc/primitives.json b/apps/radix-docs/src/api-doc/primitives.json index 4563c713..96651f95 100644 --- a/apps/radix-docs/src/api-doc/primitives.json +++ b/apps/radix-docs/src/api-doc/primitives.json @@ -948,7 +948,131 @@ "components": {} }, "slider-root.component": { - "components": {} + "components": { + "RdxSliderRootComponent": { + "description": "", + "props": { + "description": "Defines the input properties of the component.", + "values": [ + { + "name": "min", + "optional": false, + "readonly": true, + "type": "InputSignalWithTransform", + "default": "0", + "defaultValue": "0", + "description": "The minimum value for the range." + }, + { + "name": "max", + "optional": false, + "readonly": true, + "type": "InputSignalWithTransform", + "default": "100", + "defaultValue": "100", + "description": "The maximum value for the range." + }, + { + "name": "step", + "optional": false, + "readonly": true, + "type": "InputSignalWithTransform", + "default": "1", + "defaultValue": "1", + "description": "The stepping interval." + }, + { + "name": "minStepsBetweenThumbs", + "optional": false, + "readonly": true, + "type": "InputSignalWithTransform", + "default": "0", + "defaultValue": "0", + "description": "The minimum permitted steps between multiple thumbs." + }, + { + "name": "orientation", + "optional": false, + "readonly": true, + "type": "InputSignal<\"horizontal\" | \"vertical\">", + "default": "'horizontal'", + "defaultValue": "'horizontal'", + "description": "The orientation of the slider." + }, + { + "name": "disabled", + "optional": false, + "readonly": true, + "type": "InputSignalWithTransform", + "default": "false", + "defaultValue": "false", + "description": "When true, prevents the user from interacting with the slider." + }, + { + "name": "inverted", + "optional": false, + "readonly": true, + "type": "InputSignalWithTransform", + "default": "false", + "defaultValue": "false", + "description": "Whether the slider is visually inverted." + }, + { + "name": "dir", + "optional": false, + "readonly": true, + "type": "InputSignal<\"ltr\" | \"rtl\">", + "default": "'ltr'", + "defaultValue": "'ltr'", + "description": "The reading direction of the combobox when applicable." + }, + { + "name": "styleClass", + "optional": false, + "readonly": true, + "type": "InputSignal", + "default": "...", + "defaultValue": "...", + "description": "Style class of the component." + }, + { + "name": "modelValue", + "optional": false, + "readonly": true, + "type": "ModelSignal", + "default": "...", + "defaultValue": "...", + "description": "The controlled value of the slider." + } + ] + }, + "emits": { + "description": "Defines emit that determine the behavior of the component based on a given condition or report the actions that the component takes.", + "values": [ + { + "name": "valueChange", + "parameters": [ + { + "name": "value", + "type": "number[]" + } + ], + "description": "Event handler called when the slider value changes." + }, + { + "name": "valueCommit", + "parameters": [ + { + "name": "value", + "type": "number[]" + } + ], + "description": "Event handler called when the value changes at the end of an interaction.\n\nUseful when you only need to capture a final value e.g. to update a backend service." + } + ] + } + } + } }, "slider-thumb-impl.directive": { "components": {} diff --git a/apps/radix-docs/src/content/primitives/components/slider.mdx b/apps/radix-docs/src/content/primitives/components/slider.mdx index 6749eb87..f5d03693 100644 --- a/apps/radix-docs/src/content/primitives/components/slider.mdx +++ b/apps/radix-docs/src/content/primitives/components/slider.mdx @@ -36,19 +36,91 @@ description: . ### Root `RdxSliderRootComponent` + + + + + ### Track `RdxSliderTrackComponent` +The track that contains the `SliderRange`. + + ### Range `RdxSliderRangeComponent` +The range part. Must live inside `SliderTrack`. + + + ### Thumb `RdxSliderThumbComponent` +A draggable thumb. You can render multiple thumbs. + + + + ## Accessibility Adheres to the [Slider WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb). ### Keyboard Interactions + + diff --git a/packages/primitives/slider/src/slider-horizontal.component.ts b/packages/primitives/slider/src/slider-horizontal.component.ts index d1235232..922a93dc 100644 --- a/packages/primitives/slider/src/slider-horizontal.component.ts +++ b/packages/primitives/slider/src/slider-horizontal.component.ts @@ -3,11 +3,10 @@ import { booleanAttribute, Component, ElementRef, - EventEmitter, inject, input, Input, - Output, + output, signal, viewChild } from '@angular/core'; @@ -48,12 +47,12 @@ export class RdxSliderHorizontalComponent { @Input() className = ''; - @Output() slideStart = new EventEmitter(); - @Output() slideMove = new EventEmitter(); - @Output() slideEnd = new EventEmitter(); - @Output() stepKeyDown = new EventEmitter<{ event: KeyboardEvent; direction: number }>(); - @Output() endKeyDown = new EventEmitter(); - @Output() homeKeyDown = new EventEmitter(); + readonly slideStart = output(); + readonly slideMove = output(); + readonly slideEnd = output(); + readonly stepKeyDown = output<{ event: KeyboardEvent; direction: number }>(); + readonly endKeyDown = output(); + readonly homeKeyDown = output(); private readonly sliderElement = viewChild('sliderElement'); diff --git a/packages/primitives/slider/src/slider-impl.directive.ts b/packages/primitives/slider/src/slider-impl.directive.ts index cb235330..f3358cb2 100644 --- a/packages/primitives/slider/src/slider-impl.directive.ts +++ b/packages/primitives/slider/src/slider-impl.directive.ts @@ -1,10 +1,9 @@ -import { Directive, EventEmitter, inject, Output } from '@angular/core'; +import { Directive, inject, output } from '@angular/core'; import { RdxSliderRootComponent } from './slider-root.component'; import { ARROW_KEYS, PAGE_KEYS } from './utils'; @Directive({ selector: '[rdxSliderImpl]', - standalone: true, host: { role: 'slider', tabindex: '0', @@ -17,12 +16,12 @@ import { ARROW_KEYS, PAGE_KEYS } from './utils'; export class RdxSliderImplDirective { protected readonly rootContext = inject(RdxSliderRootComponent); - @Output() slideStart = new EventEmitter(); - @Output() slideMove = new EventEmitter(); - @Output() slideEnd = new EventEmitter(); - @Output() homeKeyDown = new EventEmitter(); - @Output() endKeyDown = new EventEmitter(); - @Output() stepKeyDown = new EventEmitter(); + readonly slideStart = output(); + readonly slideMove = output(); + readonly slideEnd = output(); + readonly homeKeyDown = output(); + readonly endKeyDown = output(); + readonly stepKeyDown = output(); onKeyDown(event: KeyboardEvent) { if (event.key === 'Home') { diff --git a/packages/primitives/slider/src/slider-range.component.ts b/packages/primitives/slider/src/slider-range.component.ts index 610c8d00..5baf1a66 100644 --- a/packages/primitives/slider/src/slider-range.component.ts +++ b/packages/primitives/slider/src/slider-range.component.ts @@ -4,7 +4,6 @@ import { convertValueToPercentage } from './utils'; @Component({ selector: 'rdx-slider-range', - standalone: true, host: { '[attr.data-disabled]': 'rootContext.disabled() ? "" : undefined', '[attr.data-orientation]': 'rootContext.orientation()', diff --git a/packages/primitives/slider/src/slider-root.component.ts b/packages/primitives/slider/src/slider-root.component.ts index 24041996..950ad983 100644 --- a/packages/primitives/slider/src/slider-root.component.ts +++ b/packages/primitives/slider/src/slider-root.component.ts @@ -4,14 +4,13 @@ import { booleanAttribute, Component, computed, - EventEmitter, inject, input, Input, model, numberAttribute, OnInit, - Output + output } from '@angular/core'; import { RdxSliderHorizontalComponent } from './slider-horizontal.component'; import { RdxSliderOrientationContextService } from './slider-orientation-context.service'; @@ -25,6 +24,9 @@ import { roundValue } from './utils'; +/** + * @group Components + */ @Component({ selector: 'rdx-slider', imports: [RdxSliderHorizontalComponent, RdxSliderVerticalComponent, NgIf, NgTemplateOutlet], @@ -34,7 +36,7 @@ import { (0, { transform: numberAttribute }); + /** + * The maximum value for the range. + * + * @group Props + * @defaultValue 100 + */ readonly max = input(100, { transform: numberAttribute }); + /** + * The stepping interval. + * + * @group Props + * @defaultValue 1 + */ readonly step = input(1, { transform: numberAttribute }); + /** + * The minimum permitted steps between multiple thumbs. + * + * @group Props + * @defaultValue 0 + */ readonly minStepsBetweenThumbs = input(0, { transform: numberAttribute }); + /** + * The orientation of the slider. + * + * @group Props + * @defaultValue 'horizontal' + */ readonly orientation = input<'horizontal' | 'vertical'>('horizontal'); + /** + * When true, prevents the user from interacting with the slider. + * + * @group Props + * @defaultValue false + */ readonly disabled = input(false, { transform: booleanAttribute }); + /** + * Whether the slider is visually inverted. + * + * @group Props + * @defaultValue false + */ readonly inverted = input(false, { transform: booleanAttribute }); + /** + * The reading direction of the combobox when applicable. + * + * @group Props + * @defaultValue 'ltr' + */ readonly dir = input<'ltr' | 'rtl'>('ltr'); @Input() className: string = ''; - @Output() valueChange = new EventEmitter(); - @Output() valueCommit = new EventEmitter(); - + /** + * Style class of the component. + * + * @group Props + */ + readonly styleClass = input(); + + /** + * The controlled value of the slider. + * + * @group Props + */ readonly modelValue = model([0]); + /** + * Event handler called when the slider value changes. + * + * @group Emits + */ + readonly valueChange = output(); + + /** + * Event handler called when the value changes at the end of an interaction. + * + * Useful when you only need to capture a final value e.g. to update a backend service. + * + * @group Emits + */ + readonly valueCommit = output(); + /** @ignore */ readonly valueIndexToChange = model(0); diff --git a/packages/primitives/slider/src/slider-thumb-impl.directive.ts b/packages/primitives/slider/src/slider-thumb-impl.directive.ts index 7538af95..b988fe72 100644 --- a/packages/primitives/slider/src/slider-thumb-impl.directive.ts +++ b/packages/primitives/slider/src/slider-thumb-impl.directive.ts @@ -5,7 +5,6 @@ import { convertValueToPercentage, getThumbInBoundsOffset } from './utils'; @Directive({ selector: '[rdxSliderThumbImpl]', - standalone: true, host: { role: 'slider', '[tabindex]': 'rootContext.disabled() ? undefined : 0', diff --git a/packages/primitives/slider/src/slider-thumb.component.ts b/packages/primitives/slider/src/slider-thumb.component.ts index b75f4509..c1fae6a0 100644 --- a/packages/primitives/slider/src/slider-thumb.component.ts +++ b/packages/primitives/slider/src/slider-thumb.component.ts @@ -3,7 +3,6 @@ import { RdxSliderThumbImplDirective } from './slider-thumb-impl.directive'; @Component({ selector: 'rdx-slider-thumb', - standalone: true, hostDirectives: [RdxSliderThumbImplDirective], template: ` diff --git a/packages/primitives/slider/src/slider-track.component.ts b/packages/primitives/slider/src/slider-track.component.ts index 588b4570..ca8284fe 100644 --- a/packages/primitives/slider/src/slider-track.component.ts +++ b/packages/primitives/slider/src/slider-track.component.ts @@ -3,7 +3,6 @@ import { RdxSliderRootComponent } from './slider-root.component'; @Component({ selector: 'rdx-slider-track', - standalone: true, host: { '[attr.data-disabled]': "rootContext.disabled() ? '' : undefined", '[attr.data-orientation]': 'rootContext.orientation()' diff --git a/packages/primitives/slider/src/slider-vertical.component.ts b/packages/primitives/slider/src/slider-vertical.component.ts index ea54394e..a8a0bce1 100644 --- a/packages/primitives/slider/src/slider-vertical.component.ts +++ b/packages/primitives/slider/src/slider-vertical.component.ts @@ -3,11 +3,10 @@ import { booleanAttribute, Component, ElementRef, - EventEmitter, inject, input, Input, - Output, + output, signal, viewChild } from '@angular/core'; @@ -48,12 +47,12 @@ export class RdxSliderVerticalComponent { @Input() className = ''; - @Output() slideStart = new EventEmitter(); - @Output() slideMove = new EventEmitter(); - @Output() slideEnd = new EventEmitter(); - @Output() stepKeyDown = new EventEmitter<{ event: KeyboardEvent; direction: number }>(); - @Output() endKeyDown = new EventEmitter(); - @Output() homeKeyDown = new EventEmitter(); + readonly slideStart = output(); + readonly slideMove = output(); + readonly slideEnd = output(); + readonly stepKeyDown = output<{ event: KeyboardEvent; direction: number }>(); + readonly endKeyDown = output(); + readonly homeKeyDown = output(); private readonly sliderElement = viewChild('sliderElement'); diff --git a/packages/primitives/slider/stories/slider.stories.ts b/packages/primitives/slider/stories/slider.stories.ts index ee8c6306..f1ecd935 100644 --- a/packages/primitives/slider/stories/slider.stories.ts +++ b/packages/primitives/slider/stories/slider.stories.ts @@ -37,7 +37,7 @@ export const Default: Story = { render: (args) => ({ props: args, template: html` - + @@ -51,7 +51,7 @@ export const Inverted: Story = { render: (args) => ({ props: args, template: html` - + @@ -65,7 +65,7 @@ export const Thumbs: Story = { render: (args) => ({ props: args, template: html` - + @@ -80,14 +80,14 @@ export const Vertical: Story = { render: (args) => ({ props: args, template: html` - + - + @@ -102,7 +102,7 @@ export const VerticalInverted: Story = { props: args, template: html`