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
4 changes: 4 additions & 0 deletions angular/projects/catalyst/src/lib/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox {
inputs: [
'autoComplete',
'clearable',
'dayNativeAttributes',
'dayVariants',
'disabled',
'errorUpdate',
Expand Down Expand Up @@ -353,6 +354,7 @@ export declare interface CatCheckbox extends Components.CatCheckbox {
inputs: [
'autoComplete',
'clearable',
'dayNativeAttributes',
'dayVariants',
'disabled',
'errorUpdate',
Expand Down Expand Up @@ -421,6 +423,7 @@ export declare interface CatDate extends Components.CatDate {
@ProxyCmp({
inputs: [
'a11yLabel',
'dayNativeAttributes',
'dayVariants',
'hint',
'identifier',
Expand All @@ -445,6 +448,7 @@ export declare interface CatDate extends Components.CatDate {
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: [
'a11yLabel',
'dayNativeAttributes',
'dayVariants',
'hint',
'identifier',
Expand Down
16 changes: 16 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ export namespace Components {
* @default false
*/
"clearable": boolean;
/**
* Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD).
*/
"dayNativeAttributes"?: { [date: string]: { [key: string]: string } };
/**
* Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`.
*/
Expand Down Expand Up @@ -517,6 +521,10 @@ export namespace Components {
* Clear the picker.
*/
"clear": () => Promise<void>;
/**
* Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD).
*/
"dayNativeAttributes"?: { [date: string]: { [key: string]: string } };
/**
* Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`.
*/
Expand Down Expand Up @@ -3407,6 +3415,10 @@ declare namespace LocalJSX {
* @default false
*/
"clearable"?: boolean;
/**
* Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD).
*/
"dayNativeAttributes"?: { [date: string]: { [key: string]: string } };
/**
* Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`.
*/
Expand Down Expand Up @@ -3541,6 +3553,10 @@ declare namespace LocalJSX {
* Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker.
*/
"a11yLabel"?: string;
/**
* Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD).
*/
"dayNativeAttributes"?: { [date: string]: { [key: string]: string } };
/**
* Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`.
*/
Expand Down
40 changes: 40 additions & 0 deletions core/src/components/cat-date-inline/cat-date-inline.e2e.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,49 @@
import { describe, it, expect } from 'vitest';
import { render, h } from '@stencil/vitest';
import { userEvent } from '@vitest/browser/context';

describe('cat-date-inline', () => {
it('renders', async () => {
const { root } = await render(<cat-date-inline />);
await expect.element(root).toHaveClass('hydrated');
});

it('supports day descriptions during keyboard navigation', async () => {
const { root } = await render(
<cat-date-inline
value="2026-10-20"
dayNativeAttributes={{
'2026-10-21': { 'aria-description': 'Special day' }
}}
/>
);
const picker = root as HTMLCatDateInlineElement;
const next = root.shadowRoot!.querySelector<HTMLCatButtonElement>('[data-date="2026-10-21"]')!;
const button = next.shadowRoot!.querySelector('button')!;

await picker.doFocus();
await userEvent.keyboard('{ArrowRight}');
expect(root.shadowRoot!.activeElement).toBe(next);
expect(picker.value).toBe('2026-10-20');
await expect.element(button).toHaveAccessibleName(next.a11yLabel);
await expect.element(button).toHaveAccessibleDescription('Special day');
await userEvent.keyboard('{Enter}');
expect(picker.value).toBe('2026-10-21');
});

it('updates day descriptions without moving focus', async () => {
const { root } = await render(<cat-date-inline value="2026-10-20" />);
const picker = root as HTMLCatDateInlineElement;
const selected = root.shadowRoot!.querySelector<HTMLCatButtonElement>('[data-date="2026-10-20"]')!;
const button = selected.shadowRoot!.querySelector('button')!;
await picker.doFocus();

picker.dayNativeAttributes = { '2026-10-20': { 'aria-description': 'Special day' } };
await expect.element(button).toHaveAccessibleDescription('Special day');
expect(root.shadowRoot!.activeElement).toBe(selected);

picker.dayNativeAttributes = {};
await expect.element(button).not.toHaveAttribute('aria-description');
expect(root.shadowRoot!.activeElement).toBe(selected);
});
});
19 changes: 19 additions & 0 deletions core/src/components/cat-date-inline/cat-date-inline.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ vi.mock('../cat-i18n/cat-i18n-registry', () => ({
}));

import '../cat-input/cat-input';
import '../cat-button/cat-button';
import './cat-date-inline';

describe('cat-date-inline', () => {
Expand Down Expand Up @@ -48,6 +49,24 @@ describe('cat-date-inline', () => {
);
});

it('passes day attributes while preserving labels and tab order', async () => {
const { root } = await render(
<cat-date-inline
value="2026-10-20"
dayNativeAttributes={{
'2026-10-20': { 'aria-description': 'Special day', tabindex: '-1' },
'2026-10-21': { tabindex: '0' }
}}
/>
);
const selected = root.shadowRoot?.querySelector<HTMLCatButtonElement>('[data-date="2026-10-20"]');
const next = root.shadowRoot?.querySelector<HTMLCatButtonElement>('[data-date="2026-10-21"]');

expect(selected?.a11yLabel).toBe('Tuesday, October 20, 2026');
expect(selected?.nativeAttributes).toEqual({ 'aria-description': 'Special day', tabindex: '0' });
expect(next?.nativeAttributes).toEqual({ tabindex: '-1' });
});

it('does not emit a range change when day variants trigger a render', async () => {
const { root, waitForChanges } = await render(<cat-date-inline />);
const viewChange = vi.fn();
Expand Down
10 changes: 9 additions & 1 deletion core/src/components/cat-date-inline/cat-date-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export class CatDateInline {
*/
@Prop({ mutable: true }) value?: string;

/**
* Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD).
*/
@Prop() dayNativeAttributes?: { [date: string]: { [key: string]: string } };

/**
* Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`.
*/
Expand Down Expand Up @@ -361,7 +366,10 @@ export class CatDateInline {
'date-focusable': this.canFocus(day),
'date-disabled': !this.canClick(day)
}}
nativeAttributes={!this.canFocus(day) ? { tabindex: '-1' } : {}}
nativeAttributes={{
...this.dayNativeAttributes?.[date],
tabindex: this.canFocus(day) ? '0' : '-1'
}}
variant={isStartDate || isEndDate ? 'filled' : isToday ? 'outlined' : 'text'}
a11yLabel={this.locale.toLocalStr(day)}
active={isStartDate || isEndDate || isRange}
Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-date-inline/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ An inline date picker component to select a date.
| Property | Attribute | Description | Type | Default |
| ---------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | ------------ |
| `a11yLabel` | `a11y-label` | Adds accessible label for the datepicker. The label will be read by assistive technology upon focusing the datepicker. | `string \| undefined` | `undefined` |
| `dayNativeAttributes` | -- | Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD). | `undefined \| { [date: string]: { [key: string]: string; }; }` | `undefined` |
| `dayVariants` | -- | Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. | `undefined \| { [date: string]: CatDateDayVariant; }` | `undefined` |
| `hint` | `hint` | Shows an arrow keys navigation hint. | `boolean` | `false` |
| `identifier` | `identifier` | A unique identifier for the input. | `string \| undefined` | `undefined` |
Expand Down
7 changes: 7 additions & 0 deletions core/src/components/cat-date/cat-date.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ describe('cat-date', () => {
expect(root.shadowRoot?.querySelector('cat-date-inline')?.dayVariants).toEqual(dayVariants);
});

it('forwards day native attributes to the inline date picker', async () => {
const dayNativeAttributes = { '2026-10-20': { 'aria-description': 'Special day' } };
const { root } = await render(<cat-date dayNativeAttributes={dayNativeAttributes} />);

expect(root.shadowRoot?.querySelector('cat-date-inline')?.dayNativeAttributes).toEqual(dayNativeAttributes);
});

it('forwards the visible date range from cat-date-inline', async () => {
const { root } = await render(<cat-date />);
const viewChange = vi.fn();
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/cat-date/cat-date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ export class CatDate {
*/
@Prop({ mutable: true }) value?: string;

/**
* Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD).
*/
@Prop() dayNativeAttributes?: { [date: string]: { [key: string]: string } };

/**
* Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`.
*/
Expand Down Expand Up @@ -323,6 +328,7 @@ export class CatDate {
max={this.max}
value={this.value}
dayVariants={this.dayVariants}
dayNativeAttributes={this.dayNativeAttributes}
hint
weeks
noClear
Expand Down
1 change: 1 addition & 0 deletions core/src/components/cat-date/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ A date input component to select a date from a calendar in a dropdown.
| ------------------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| `autoComplete` | `auto-complete` | Hint for form autofill feature. | `string` | `'off'` |
| `clearable` | `clearable` | Whether the input should show a clear button. | `boolean` | `false` |
| `dayNativeAttributes` | -- | Attributes for native day buttons, keyed by local ISO date (YYYY-MM-DD). | `undefined \| { [date: string]: { [key: string]: string; }; }` | `undefined` |
| `dayVariants` | -- | Maps local ISO dates (YYYY-MM-DD) to semantic theme variants, e.g. `{ '2026-10-20': 'danger' }`. | `undefined \| { [date: string]: CatDateDayVariant; }` | `undefined` |
| `disabled` | `disabled` | Whether the input is disabled. | `boolean` | `false` |
| `errorUpdate` | `error-update` | Fine-grained control over when the errors are shown. Can be `false` to never show errors, `true` to show errors on blur, or a number to show errors change with the given delay in milliseconds or immediately on blur. | `boolean \| number` | `0` |
Expand Down
Loading