@jobber/components-native 0.116.0 → 0.116.1

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.116.0",
3
+ "version": "0.116.1",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -125,5 +125,5 @@
125
125
  "react-native-screens": ">=4.18.0",
126
126
  "react-native-svg": ">=12.0.0"
127
127
  },
128
- "gitHead": "d58819450555e691966244925a7152575316b0f5"
128
+ "gitHead": "d324e138d0e3c27cf0e54dac5d40b2c2d7e9ab82"
129
129
  }
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
+ import { Pressable, StyleSheet } from "react-native";
2
3
  import { fireEvent, render, screen, within, } from "@testing-library/react-native";
3
- import { Pressable } from "react-native";
4
4
  import { SelectRoot } from "./SelectRoot";
5
5
  import { SelectTrigger } from "./components/SelectTrigger";
6
6
  import { SelectLabel } from "./components/SelectLabel";
@@ -117,10 +117,44 @@ describe("SelectRoot label placement", () => {
117
117
  React.createElement(SelectTrigger, null,
118
118
  React.createElement(SelectPrimitive.Value, { placeholder: "Select an option" }))));
119
119
  }
120
+ function getTriggerContent() {
121
+ const trigger = screen.getByTestId("ATL-Select-Trigger");
122
+ const content = trigger.children[0];
123
+ // Unwrap the mocked View to return its native host element.
124
+ return content.children[0];
125
+ }
126
+ it.each([
127
+ { labelPlacement: "inside" },
128
+ { labelPlacement: "above" },
129
+ { readOnly: true },
130
+ { disabled: true },
131
+ ])("centers a value without an inside label (%j)", props => {
132
+ var _a;
133
+ renderRoot(Object.assign(Object.assign({}, props), { defaultValue: { value: "tor", label: "Toronto" } }));
134
+ const content = getTriggerContent();
135
+ expect(content).toHaveStyle({
136
+ flexDirection: "row",
137
+ alignItems: "center",
138
+ });
139
+ expect((_a = StyleSheet.flatten(content.props.style).paddingTop) !== null && _a !== void 0 ? _a : 0).toBe(0);
140
+ });
141
+ it("centers the placeholder when the composed label is above the trigger", () => {
142
+ renderComposed({ labelPlacement: "above" });
143
+ expect(getTriggerContent()).toHaveStyle({
144
+ flexDirection: "row",
145
+ alignItems: "center",
146
+ });
147
+ });
120
148
  it("places the label inside the trigger by default (labelPlacement inside)", () => {
121
149
  renderComposed();
122
150
  const trigger = screen.getByTestId("ATL-Select-Trigger");
123
151
  expect(within(trigger).getByText("City", hidden)).toBeDefined();
152
+ expect(getTriggerContent()).toHaveStyle({
153
+ paddingTop: tokens["space-small"] - tokens["space-smallest"],
154
+ });
155
+ expect(getTriggerContent()).not.toHaveStyle({
156
+ flexDirection: "row",
157
+ });
124
158
  });
125
159
  it("places the label above the trigger with labelPlacement='above'", () => {
126
160
  renderComposed({ labelPlacement: "above" });
@@ -14,13 +14,16 @@ import { Icon } from "../../Icon";
14
14
  */
15
15
  export function SelectTrigger({ children, testID, ref, }) {
16
16
  const styles = useStyles();
17
- const { invalid, readOnly, accessibilityLabel, labelPlacement } = useSelectFieldState();
17
+ const { invalid, readOnly, accessibilityLabel, labelPlacement, labelContent, } = useSelectFieldState();
18
18
  const { open, value, disabled } = useRootContext();
19
19
  const isDisabled = disabled !== null && disabled !== void 0 ? disabled : false;
20
20
  // `disabled` wins over `readOnly`.
21
21
  const isReadOnly = !isDisabled && (readOnly !== null && readOnly !== void 0 ? readOnly : false);
22
- const isInsideLabel = labelPlacement === "inside";
23
- const content = (React.createElement(View, { style: [styles.content, isInsideLabel && styles.contentInside] },
22
+ const isInsideLabel = labelPlacement === "inside" && labelContent != null;
23
+ const content = (React.createElement(View, { style: [
24
+ styles.content,
25
+ isInsideLabel ? styles.contentInside : styles.contentWithoutLabel,
26
+ ] },
24
27
  isInsideLabel && React.createElement(FieldLabel, null),
25
28
  children));
26
29
  if (isReadOnly) {
@@ -4,6 +4,11 @@ export const useStyles = buildThemedStyles(tokens => ({
4
4
  flex: 1,
5
5
  justifyContent: "center",
6
6
  },
7
+ // Keep the Value's flex horizontal when there is no label to stack above it.
8
+ contentWithoutLabel: {
9
+ flexDirection: "row",
10
+ alignItems: "center",
11
+ },
7
12
  // Inside-label placement: the Value's flex fills the column vertically and
8
13
  // would otherwise pin the label flush to the top. This top inset gives the
9
14
  // label the same breathing room as the shared input chrome's mini-label.