@eintrek/erp-theme 1.4.6 → 1.4.7

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.
@@ -1,6 +1,6 @@
1
1
  import { Select as SelectPrimitive } from "radix-ui";
2
2
  import * as React from "react";
3
- declare function Select({ onValueChange, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
3
+ declare function Select({ onValueChange, onOpenChange, open, defaultOpen, ...props }: React.ComponentProps<typeof SelectPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
4
4
  declare function SelectGroup({ ...props }: React.ComponentProps<typeof SelectPrimitive.Group>): import("react/jsx-runtime").JSX.Element;
5
5
  declare function SelectValue({ ...props }: React.ComponentProps<typeof SelectPrimitive.Value>): import("react/jsx-runtime").JSX.Element;
6
6
  declare function SelectTrigger({ className, size, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
package/dist/index.esm.js CHANGED
@@ -15986,14 +15986,22 @@ function ScrollBar({ className, orientation = "vertical", ...props }) {
15986
15986
  "h-2.5 flex-col border-t border-t-transparent", className), ...props, children: jsx(ScrollAreaPrimitive.ScrollAreaThumb, { "data-slot": "scroll-area-thumb", className: "bg-border relative flex-1 rounded-full" }) }));
15987
15987
  }
15988
15988
 
15989
- function Select({ onValueChange, ...props }) {
15990
- return (jsx(SelectPrimitive.Root, { "data-slot": "select", ...props, onValueChange: value => {
15991
- // Swallow the empty value Radix emits on its own.
15989
+ function Select({ onValueChange, onOpenChange, open, defaultOpen, ...props }) {
15990
+ // Tracked in a ref, not state: this only needs to be readable inside the
15991
+ // callback below, and putting it in state would re-render on every open.
15992
+ const isOpenRef = React.useRef(defaultOpen ?? false);
15993
+ if (open !== undefined)
15994
+ isOpenRef.current = open;
15995
+ return (jsx(SelectPrimitive.Root, { "data-slot": "select", ...props, open: open, defaultOpen: defaultOpen, onOpenChange: next => {
15996
+ isOpenRef.current = next;
15997
+ onOpenChange?.(next);
15998
+ }, onValueChange: value => {
15999
+ // Drop ONLY the empty value Radix echoes back on its own.
15992
16000
  //
15993
- // Radix keeps a hidden native <select> so the control participates in
16001
+ // Radix keeps a hidden native <select> so the control works inside
15994
16002
  // real forms. Whenever the controlled value changes it assigns that
15995
16003
  // value to the native node and dispatches a synthetic change event,
15996
- // which comes back out through onValueChange:
16004
+ // which comes straight back out through onValueChange:
15997
16005
  //
15998
16006
  // setValue.call(select, selectValue);
15999
16007
  // select.dispatchEvent(new Event("change", { bubbles: true }));
@@ -16001,24 +16009,23 @@ function Select({ onValueChange, ...props }) {
16001
16009
  // onChange: (event) => onValueChange(event.target.value)
16002
16010
  //
16003
16011
  // The native <option> list is registered by SelectItem, and the items
16004
- // live inside SelectContent — which is portalled and only mounted
16005
- // while the menu is open. So on a closed select the option for the
16006
- // incoming value usually does not exist yet, the DOM refuses the
16007
- // assignment, `select.value` collapses to "", and that empty string is
16008
- // what every consumer receives.
16012
+ // live inside SelectContent — portalled, and only mounted while the
16013
+ // menu is open. On a closed select the option for the incoming value
16014
+ // usually does not exist yet, the DOM refuses the assignment,
16015
+ // `select.value` collapses to "", and that empty string reaches the
16016
+ // consumer. In a form this lands exactly when saved data arrives: the
16017
+ // field is set to its stored value, Radix echoes "", and the handler
16018
+ // writes that back — enum fields then snap to their fallback and zod
16019
+ // rejects the submit with "received ''".
16009
16020
  //
16010
- // In practice this fires exactly when server data lands in a form:
16011
- // the field is set to the saved value, Radix echoes back "", and the
16012
- // handler writes it into form state. Fields normalised through an
16013
- // enum/fallback then snap to their default; fields validated by zod
16014
- // fail on submit with "received ''".
16015
- //
16016
- // A genuine selection can never be empty — that path is
16017
- // `context.onValueChange(value)` from SelectItem's handleSelect, using
16018
- // the item's own value — so dropping "" costs nothing. Consumers that
16019
- // really want a "none" option should give it an explicit sentinel
16020
- // value; Radix reserves "" for the placeholder.
16021
- if (value === "")
16021
+ // The open check is what keeps a real "none" option working. Radix
16022
+ // does NOT forbid <SelectItem value="">, and picking one is a
16023
+ // legitimate way to clear a selection. A user pick always arrives
16024
+ // while the menu is still open SelectItem's handleSelect calls
16025
+ // onValueChange(value) BEFORE onOpenChange(false) whereas the echo
16026
+ // above fires from an effect with the menu closed. So only the closed
16027
+ // case is suppressed.
16028
+ if (value === "" && !isOpenRef.current)
16022
16029
  return;
16023
16030
  onValueChange?.(value);
16024
16031
  } }));