Skip to content

Commit

Permalink
make name prop consistent with date field and range field
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Aug 2, 2024
1 parent 4cffcf0 commit e748967
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let {
id = useId(),
ref = $bindable(null),
name = "",
children,
child,
...restProps
Expand All @@ -20,6 +21,7 @@
() => ref,
(v) => (ref = v)
),
name: box.with(() => name),
});
const mergedProps = $derived(mergeProps(restProps, inputState.props));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
locale = "en",
maxValue,
minValue,
name = "",
onPlaceholderChange = noop,
onValueChange = noop,
placeholder = $bindable(),
Expand Down Expand Up @@ -64,7 +63,6 @@
readonly: box.with(() => readonly),
readonlySegments: box.with(() => readonlySegments),
required: box.with(() => required),
name: box.with(() => name),
});
</script>

Expand Down
23 changes: 17 additions & 6 deletions packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export type DateFieldRootStateProps = WritableBoxedValues<{
hourCycle: HourCycle | undefined;
locale: string;
hideTimeZone: boolean;
name: string;
required: boolean;
}>;

Expand All @@ -91,7 +90,6 @@ export class DateFieldRootState {
hourCycle: DateFieldRootStateProps["hourCycle"];
locale: DateFieldRootStateProps["locale"];
hideTimeZone: DateFieldRootStateProps["hideTimeZone"];
name: DateFieldRootStateProps["name"];
required: DateFieldRootStateProps["required"];
descriptionId = useId();
formatter: Formatter;
Expand All @@ -107,6 +105,7 @@ export class DateFieldRootState {
states = initSegmentStates();
dayPeriodNode = $state<HTMLElement | null>(null);
rangeRoot: DateRangeFieldRootState | undefined = undefined;
name = $state("");

constructor(props: DateFieldRootStateProps, rangeRoot?: DateRangeFieldRootState) {
this.rangeRoot = rangeRoot;
Expand All @@ -128,7 +127,6 @@ export class DateFieldRootState {
this.locale = rangeRoot ? rangeRoot.locale : props.locale;
this.hideTimeZone = rangeRoot ? rangeRoot.hideTimeZone : props.hideTimeZone;
this.required = rangeRoot ? rangeRoot.required : props.required;
this.name = props.name;
this.formatter = createFormatter(this.locale.current);
this.initialSegments = initializeSegmentValues(this.inferredGranularity);
this.segmentValues = this.initialSegments;
Expand Down Expand Up @@ -185,6 +183,10 @@ export class DateFieldRootState {
});
}

setName = (name: string) => {
this.name = name;
};

/**
* Sets the field node for the `DateFieldRootState` instance. We use this method so we can
* keep `#fieldNode` private to prevent accidental usage of the incorrect field node.
Expand Down Expand Up @@ -569,17 +571,26 @@ export class DateFieldRootState {
}
}

type DateFieldInputStateProps = WithRefProps;
type DateFieldInputStateProps = WithRefProps &
ReadableBoxedValues<{
name: string;
}>;

class DateFieldInputState {
#id: DateFieldInputStateProps["id"];
#ref: DateFieldInputStateProps["ref"];
#name: DateFieldInputStateProps["name"];
root: DateFieldRootState;

constructor(props: DateFieldInputStateProps, root: DateFieldRootState) {
this.#id = props.id;
this.#ref = props.ref;
this.root = root;
this.#name = props.name;

$effect(() => {
this.root.setName(this.#name.current);

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should have no axe violations". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should populate segment with value - `CalendarDate`". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should populate segment with value - `CalendarDateTime`". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should populate segment with value - `ZonedDateTime`". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should navigate between the fields". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should navigate between the fields - right to left". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should respect `bind:value` to the value". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

Unhandled error

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ process_deferred ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:570:2 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ node:internal/process/task_queues:140:7 ❯ AsyncResource.runInAsyncScope node:async_hooks:206:9 ❯ AsyncResource.runMicrotask node:internal/process/task_queues:137:8 ❯ processTicksAndRejections node:internal/process/task_queues:95:5 This error originated in "src/tests/date-range-field/DateRangeField.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should render an input for the start and end". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

src/tests/date-range-field/DateRangeField.spec.ts > date range field > should have no axe violations

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ Module.flush_sync ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:705:3 ❯ Module.flushSync ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/index-client.js:193:24 ❯ Module.mount ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/core/modern.svelte.js:32:24 ❯ Module.render ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/pure.js:71:43 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ Module.flushSync ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/index-client.js:193:24 ❯ Module.mount ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/core/modern.svelte.js:32:24 ❯ Module.render ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/pure.js:71:43 ❯ setup src/tests/date-range-field/DateRangeField.spec.ts:27:19

Check failure on line 592 in packages/bits-ui/src/lib/bits/date-field/date-field.svelte.ts

View workflow job for this annotation

GitHub Actions / Test

src/tests/date-range-field/DateRangeField.spec.ts > date range field > should populate segment with value - `CalendarDate`

TypeError: Cannot read properties of undefined (reading 'current') in $effect in date-range-field-input.svelte in date-range-field.svelte in DateRangeFieldTest.svelte ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ update_reaction ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:297:56 ❯ update_effect ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:472:18 ❯ flush_queued_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:543:4 ❯ flush_queued_root_effects ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:523:5 ❯ Module.flush_sync ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/internal/client/runtime.js:705:3 ❯ Module.flushSync ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/index-client.js:193:24 ❯ Module.mount ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/core/modern.svelte.js:32:24 ❯ Module.render ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/pure.js:71:43 ❯ $effect src/lib/bits/date-field/date-field.svelte.ts:592:33 ❯ Module.flushSync ../../node_modules/.pnpm/svelte@5.0.0-next.199/node_modules/svelte/src/index-client.js:193:24 ❯ Module.mount ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/core/modern.svelte.js:32:24 ❯ Module.render ../../node_modules/.pnpm/@testing-library+svelte@5.2.1_svelte@5.0.0-next.199_vite@5.3.5_@types+node@20.14.13__vitest@2_jmcr2irjvjg4col5xy4hth7vay/node_modules/@testing-library/svelte/src/pure.js:71:43 ❯ setup src/tests/date-range-field/DateRangeField.spec.ts:27:19
});

useRefById({
id: this.#id,
Expand Down Expand Up @@ -614,7 +625,7 @@ class DateFieldInputState {

class DateFieldHiddenInputState {
#root: DateFieldRootState;
shouldRender = $derived.by(() => this.#root.name.current !== "");
shouldRender = $derived.by(() => this.#root.name !== "");
isoValue = $derived.by(() =>
this.#root.value.current ? this.#root.value.current.toString() : ""
);
Expand All @@ -625,7 +636,7 @@ class DateFieldHiddenInputState {

props = $derived.by(() => {
return {
name: this.#root.name.current,
name: this.#root.name,
value: this.isoValue,
required: this.#root.required.current,
"aria-hidden": getAriaHidden(true),
Expand Down
21 changes: 12 additions & 9 deletions packages/bits-ui/src/lib/bits/date-field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ export type DateFieldRootPropsWithoutHTML = {
*/
hideTimeZone?: boolean;

/**
* The name to use for the hidden input element of the date field,
* which is used to submit the ISO string value of the date field
* to a server. If not provided, the hidden input element will not
* be rendered.
*/
name?: string;

/**
* Whether or not the hidden input of the date field requires a value
* to be submitted.
Expand All @@ -138,7 +130,18 @@ export type DateFieldRootProps = DateFieldRootPropsWithoutHTML;

export type DateFieldInputSnippetProps = { segments: Array<{ part: SegmentPart; value: string }> };

export type DateFieldInputPropsWithoutHTML = WithChild<{}, DateFieldInputSnippetProps>;
export type DateFieldInputPropsWithoutHTML = WithChild<
{
/**
* The name to use for the hidden input element of the date field,
* which is used to submit the ISO string value of the date field
* to a server. If not provided, the hidden input element will not
* be rendered.
*/
name?: string;
},
DateFieldInputSnippetProps
>;

export type DateFieldInputProps = DateFieldInputPropsWithoutHTML &
Without<PrimitiveDivAttributes, DateFieldInputPropsWithoutHTML>;
Expand Down
8 changes: 5 additions & 3 deletions packages/bits-ui/src/tests/date-field/DateFieldTest.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<script lang="ts" context="module">
import { DateField, type DateFieldRootProps, type WithoutChildrenOrChild } from "$lib/index.js";
export type DateFieldTestProps = WithoutChildrenOrChild<DateFieldRootProps>;
export type DateFieldTestProps = WithoutChildrenOrChild<DateFieldRootProps> & {
name?: string;
};
</script>

<script lang="ts">
let { value, placeholder, ...restProps }: DateFieldTestProps = $props();
let { value, placeholder, name, ...restProps }: DateFieldTestProps = $props();
</script>

<main>
<div data-testid="value">{value}</div>
<DateField.Root bind:value bind:placeholder {...restProps}>
<div>
<DateField.Label data-testid="label">Label</DateField.Label>
<DateField.Input data-testid="input">
<DateField.Input data-testid="input" {name}>
{#snippet children({ segments })}
{#each segments as { part, value }}
<DateField.Segment
Expand Down
2 changes: 1 addition & 1 deletion sites/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

These are outstanding tasks that need to be completed or addressed before the project is ready for release.

- [ ] Make the component which receives the `name` prop consistent across the `DateField` and `DateRangeField`, `DatePicker` and `DateRangePicker` components.
- [x] Make the component which receives the `name` prop consistent across the `DateField` and `DateRangeField`, `DatePicker` and `DateRangePicker` components.
- [ ] Determine how to handle validation for the various date and time components. Ideally in a way that those using libraries like `sveltekit-superforms` and those that aren't can both benefit from.
- [ ] Determine the ideal approach for managing the `data-<component>` attributes.
- [ ] Expose the various `open` states via snippet props for all compoents with the `forceMount` prop for controlled transitions and animations. Thinking more about this, we don't need to pass it via `children`, only via the `child` snippet.
Expand Down

0 comments on commit e748967

Please sign in to comment.