@delacour/react-native-bottom-sheet 0.6.0-alpha.20261102152310 → 0.6.0-alpha.20261103104147

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-bottom-sheet",
3
- "version": "0.6.0-alpha.20261102152310",
3
+ "version": "0.6.0-alpha.20261103104147",
4
4
  "description": "Headless bottom sheet engine for React Native — no tokens, no className",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -0,0 +1,39 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { mergeProps } from "./merge-props";
3
+
4
+ describe("mergeProps", () => {
5
+ test("child props override slot props", () => {
6
+ expect(mergeProps({ testID: "slot" }, { testID: "child" })).toMatchObject({ testID: "child" });
7
+ });
8
+
9
+ test("chains event handlers slot-first", () => {
10
+ const order: string[] = [];
11
+ const merged = mergeProps<{ onPress?: () => void }>(
12
+ { onPress: () => order.push("slot") },
13
+ { onPress: () => order.push("child") }
14
+ );
15
+ merged.onPress?.();
16
+ expect(order).toEqual(["slot", "child"]);
17
+ });
18
+
19
+ test("keeps the slot's handler when the child forwards an undefined one", () => {
20
+ // `<BottomSheet.Trigger asChild><Button onPress={maybe} /></BottomSheet.Trigger>`:
21
+ // the trigger's open handler must survive a child's unset optional `onPress`.
22
+ let opened = false;
23
+ const merged = mergeProps<{ onPress?: () => void }>(
24
+ {
25
+ onPress: () => {
26
+ opened = true;
27
+ },
28
+ },
29
+ { onPress: undefined }
30
+ );
31
+ merged.onPress?.();
32
+ expect(opened).toBe(true);
33
+ });
34
+
35
+ test("flattens style into an array with the child last", () => {
36
+ const merged = mergeProps({ style: { opacity: 1 } }, { style: { opacity: 0.5 } });
37
+ expect(merged.style).toEqual([{ opacity: 1 }, { opacity: 0.5 }]);
38
+ });
39
+ });
@@ -8,7 +8,9 @@ function isEventHandlerKey(key: string): boolean {
8
8
  * Merges a slot's own props with those of the element it renders into.
9
9
  *
10
10
  * Child props win, with two exceptions: event handlers are chained
11
- * slot-first-then-child so neither side is silently dropped, and `style` is
11
+ * slot-first-then-child so neither side is silently dropped (a child's unset
12
+ * handler keeps the slot's: `<Button onPress={maybe}>` forwarding `undefined`
13
+ * is not a request to remove one), and `style` is
12
14
  * flattened into an array with the child last (React Native resolves style
13
15
  * arrays left to right).
14
16
  *
@@ -30,6 +32,10 @@ export function mergeProps<T extends UnknownProps>(slotProps: UnknownProps, chil
30
32
  continue;
31
33
  }
32
34
 
35
+ if (isEventHandlerKey(key) && typeof slotValue === "function" && childValue == null) {
36
+ continue;
37
+ }
38
+
33
39
  if (key === "style" && slotValue != null && childValue != null) {
34
40
  merged[key] = [slotValue, childValue].flat();
35
41
  continue;