bits-ui 2.14.2 → 2.14.4

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.
@@ -43,6 +43,8 @@
43
43
 
44
44
  const defaultPlaceholder = getDefaultDate({
45
45
  defaultValue: value,
46
+ minValue,
47
+ maxValue,
46
48
  });
47
49
 
48
50
  function handleDefaultPlaceholder() {
@@ -134,6 +134,10 @@ export class CommandRootState {
134
134
  if (!this._commandState.value || !this.#isInitialMount) {
135
135
  this.#selectFirstItem();
136
136
  }
137
+ else if (this.#isInitialMount && this._commandState.value) {
138
+ // scroll the initial value into view if it exists
139
+ this.#scrollInitialValue();
140
+ }
137
141
  return;
138
142
  }
139
143
  const scores = this._commandState.filtered.items;
@@ -216,6 +220,19 @@ export class CommandRootState {
216
220
  this.#isInitialMount = false;
217
221
  });
218
222
  }
223
+ /**
224
+ * Scrolls the initial value into view if it exists and is not the first item.
225
+ * Called during initial mount when a value is provided.
226
+ */
227
+ #scrollInitialValue() {
228
+ afterTick(() => {
229
+ const shouldPreventScroll = this.opts.disableInitialScroll.current;
230
+ if (!shouldPreventScroll) {
231
+ this.#scrollSelectedIntoView();
232
+ }
233
+ this.#isInitialMount = false;
234
+ });
235
+ }
219
236
  /**
220
237
  * Updates filtered items/groups based on search.
221
238
  * Recalculates scores and filtered count.
@@ -30,6 +30,7 @@
30
30
  { style: { pointerEvents: "auto" } },
31
31
  {
32
32
  style: restProps.style,
33
+ tabindex: restProps.tabindex,
33
34
  }
34
35
  )
35
36
  );
@@ -34,6 +34,8 @@
34
34
  const defaultPlaceholder = getDefaultDate({
35
35
  granularity,
36
36
  defaultValue: value,
37
+ minValue,
38
+ maxValue,
37
39
  });
38
40
 
39
41
  if (setPlaceholder) {
@@ -53,6 +53,8 @@
53
53
  const defaultPlaceholder = getDefaultDate({
54
54
  granularity,
55
55
  defaultValue: value,
56
+ minValue,
57
+ maxValue,
56
58
  });
57
59
 
58
60
  function handleDefaultPlaceholder() {
@@ -44,7 +44,12 @@
44
44
 
45
45
  function handleDefaultPlaceholder() {
46
46
  if (placeholder !== undefined) return;
47
- const defaultPlaceholder = getDefaultDate({ granularity, defaultValue: value?.start });
47
+ const defaultPlaceholder = getDefaultDate({
48
+ granularity,
49
+ defaultValue: value?.start,
50
+ minValue,
51
+ maxValue,
52
+ });
48
53
  placeholder = defaultPlaceholder;
49
54
  }
50
55
 
@@ -85,6 +85,8 @@
85
85
  const defaultPlaceholder = getDefaultDate({
86
86
  granularity,
87
87
  defaultValue: value?.start,
88
+ minValue,
89
+ maxValue,
88
90
  });
89
91
 
90
92
  function handleDefaultPlaceholder() {
@@ -50,6 +50,8 @@
50
50
 
51
51
  const defaultPlaceholder = getDefaultDate({
52
52
  defaultValue: value?.start,
53
+ minValue,
54
+ maxValue,
53
55
  });
54
56
 
55
57
  function handleDefaultPlaceholder() {
@@ -2,6 +2,8 @@ import { CalendarDateTime, type DateValue, ZonedDateTime } from "@internationali
2
2
  import type { DateMatcher, Granularity, TimeGranularity, TimeValue } from "../../shared/date/types.js";
3
3
  type GetDefaultDateProps = {
4
4
  defaultValue?: DateValue | DateValue[] | undefined;
5
+ minValue?: DateValue;
6
+ maxValue?: DateValue;
5
7
  granularity?: Granularity;
6
8
  };
7
9
  type GetDefaultTimeProps = {
@@ -11,7 +13,7 @@ type GetDefaultTimeProps = {
11
13
  /**
12
14
  * A helper function used throughout the various date builders
13
15
  * to generate a default `DateValue` using the `defaultValue`,
14
- * `defaultPlaceholder`, and `granularity` props.
16
+ * `defaultPlaceholder`, `minValue`, `maxValue`, and `granularity` props.
15
17
  *
16
18
  * It's important to match the `DateValue` type being used
17
19
  * elsewhere in the builder, so they behave according to the
@@ -10,7 +10,7 @@ const defaultTimeDefaults = {
10
10
  /**
11
11
  * A helper function used throughout the various date builders
12
12
  * to generate a default `DateValue` using the `defaultValue`,
13
- * `defaultPlaceholder`, and `granularity` props.
13
+ * `defaultPlaceholder`, `minValue`, `maxValue`, and `granularity` props.
14
14
  *
15
15
  * It's important to match the `DateValue` type being used
16
16
  * elsewhere in the builder, so they behave according to the
@@ -19,7 +19,7 @@ const defaultTimeDefaults = {
19
19
  */
20
20
  export function getDefaultDate(opts) {
21
21
  const withDefaults = { ...defaultDateDefaults, ...opts };
22
- const { defaultValue, granularity } = withDefaults;
22
+ const { defaultValue, granularity, minValue, maxValue } = withDefaults;
23
23
  if (Array.isArray(defaultValue) && defaultValue.length) {
24
24
  return defaultValue[defaultValue.length - 1];
25
25
  }
@@ -27,7 +27,13 @@ export function getDefaultDate(opts) {
27
27
  return defaultValue;
28
28
  }
29
29
  else {
30
- const date = new Date();
30
+ let date = new Date();
31
+ if (minValue && date < minValue.toDate(getLocalTimeZone())) {
32
+ date = minValue.toDate(getLocalTimeZone());
33
+ }
34
+ else if (maxValue && date > maxValue.toDate(getLocalTimeZone())) {
35
+ date = maxValue.toDate(getLocalTimeZone());
36
+ }
31
37
  const year = date.getFullYear();
32
38
  const month = date.getMonth() + 1;
33
39
  const day = date.getDate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "2.14.2",
3
+ "version": "2.14.4",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",