> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Date Field Yearless Range – Code

> A date range picker for selecting start and end dates without year, useful for recurring date ranges.

export const LiveCode = ({children, customHeight, clickToLoad, example, fullWidth, fullHeight, hideCodeInLiveCode, screenshot, screenshotOnly, showCode: showCodeProp}) => {
  const SCREENSHOTS_BASE = "https://servicetitan.github.io/anvil2-docs-live-code/screenshots";
  const STACKBLITZ_BASE = "https://stackblitz.com/github/servicetitan/anvil2-docs-live-code/tree/main/examples";
  const [showCodeBlock, setShowCodeBlock] = useState(showCodeProp ?? false);
  const [isLocalOverride, setIsLocalOverride] = useState(false);
  useEffect(() => {
    const examplePath = `/images/live-code-screenshots-tmp/${example}.png`;
    fetch(examplePath, {
      method: "HEAD"
    }).then(r => {
      if (r.ok) setIsLocalOverride(true);
    }).catch(() => {});
  }, [example]);
  const screenshotBase = isLocalOverride ? "/images/live-code-screenshots-tmp" : SCREENSHOTS_BASE;
  if (screenshotOnly) {
    return <Frame className="flex flex-col">
        <div className="flex dark:hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#FFFFFF"
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>
        <div className="hidden dark:flex" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined,
      background: "#141414"
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>
      </Frame>;
  }
  if (screenshot) {
    return <Frame className="flex flex-col -mb-2">
        <div className="flex dark:hidden bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}.png, ${screenshotBase}/${example}-2x.png 2x`} src={`${screenshotBase}/${example}.png`} alt={example} noZoom />
        </div>

        <div className="hidden dark:flex bg-white dark:bg-codeblock border border-gray-950/10 dark:border-white/10 dark:twoslash-dark rounded-2xl overflow-hidden" style={{
      background: "#141414",
      justifyContent: "center",
      alignItems: "center",
      width: fullWidth ? "100%" : "50%",
      minHeight: fullHeight ? "284px" : undefined
    }}>
          <img srcset={`${screenshotBase}/${example}-dark.png, ${screenshotBase}/${example}-dark-2x.png 2x`} src={`${screenshotBase}/${example}-dark.png`} alt={example} noZoom />
        </div>

        <div className="flex justify-end items-center text-xs py-2 px-1 gap-4">
          {!showCodeProp ? <button className="inline-flex justify-end items-center text-gray-700 dark:text-gray-50 hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1 cursor-pointer" onClick={() => setShowCodeBlock(!showCodeBlock)} style={{
      appearance: "none"
    }}>
              <Icon icon="code" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
              <span>{showCodeBlock ? "Hide code" : "Show code"}</span>
            </button> : null}

          <a className="inline-flex justify-end items-center hover:text-blue-500 dark:hover:text-blue-300 transition-colors group self-end gap-1" href={`${STACKBLITZ_BASE}/${example}?file=src/App.tsx`} target="_blank" rel="noreferrer">
            <Icon icon="bolt" size="12px" className="group-hover:bg-blue-500 dark:group-hover:bg-blue-300" />
            <span>StackBlitz demo</span>
          </a>
        </div>

        <div className="grid transition-[grid-template-rows] duration-300 ease-in-out overflow-auto overflow-y-hidden overflow-x-auto" style={showCodeBlock ? {
      gridTemplateRows: "1fr"
    } : {
      gridTemplateRows: "0fr"
    }}>
          <div style={{
      minHeight: 0,
      overflowX: "auto",
      overflowY: "hidden",
      marginBlockStart: "-1.25rem",
      marginBlockEnd: "-1.5rem"
    }}>
            {children}
          </div>
        </div>
      </Frame>;
  } else {
    return <div style={{
      display: "flex",
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px",
      resize: "vertical",
      overflow: "auto"
    }}>
        <iframe title={example} style={{
      flex: 1,
      width: fullWidth ? "100%" : "50%",
      minHeight: customHeight ? customHeight : "316px"
    }} src={`${STACKBLITZ_BASE}/${example}?embed=1&hideNavigation=1&hideExplorer=1&terminalHeight=0&file=src/App.tsx${clickToLoad ? "&ctl=1" : ""}${hideCodeInLiveCode ? "&view=preview" : ""}`} allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" />
      </div>;
  }
};

<Tabs>
  <Tab title="Implementation">
    <LiveCode showCode example="datefieldyearlessrange-playground" fullWidth screenshot>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange } from "@servicetitan/anvil2";

      function App() {
        return <DateFieldYearlessRange label="Date Range" />;
      }

      export default App;
      ```
    </LiveCode>

    ## Common Examples

    ```tsx theme={null}
    import { DateFieldYearlessRange } from "@servicetitan/anvil2";

    function ExampleComponent() {
      return <DateFieldYearlessRange label="Date Range" />;
    }
    ```

    ### Controlled vs Uncontrolled

    The `DateFieldYearlessRange` component can be used in controlled or uncontrolled mode.

    #### Uncontrolled

    Use `defaultValue` to set an initial value without controlling the state.

    <LiveCode showCode example="datefieldyearlessrange-uncontrolled" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange } from "@servicetitan/anvil2";

      function App() {
        return (
          <DateFieldYearlessRange
            label="Season"
            defaultValue={{
              startDate: { month: 6, day: 1 },
              endDate: { month: 8, day: 31 },
            }}
          />
        );
      }

      export default App;
      ```
    </LiveCode>

    #### Controlled

    Use `value` and `onChange` for full control over the component state.

    <LiveCode showCode example="datefieldyearlessrange-controlled" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import {
        DateFieldYearlessRange,
        type DateFieldYearlessRangeChange,
      } from "@servicetitan/anvil2";
      import { useState } from "react";

      function App() {
        const [dateRange, setDateRange] = useState<DateFieldYearlessRangeChange>({
          startDate: { month: 1, day: 1 },
          endDate: { month: 12, day: 31 },
        });

        return (
          <DateFieldYearlessRange
            label="Annual Period"
            value={dateRange}
            onChange={setDateRange}
          />
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Date Format Modes

    The component supports two date format modes: `mm/dd` (default) and `dd/mm`.

    <LiveCode showCode example="datefieldyearlessrange-mode" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange, Flex } from "@servicetitan/anvil2";

      function App() {
        return (
          <Flex direction="column" gap="4" style={{ minWidth: "384px" }}>
            {/** US format (default) */}
            <DateFieldYearlessRange label="US Format" mode="mm/dd" />

            {/** International format */}
            <DateFieldYearlessRange label="International Format" mode="dd/mm" />
          </Flex>
        );
      }

      export default App;
      ```
    </LiveCode>

    ### With Validation

    Show error states when validation fails.

    <LiveCode showCode example="datefieldyearlessrange-error" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange } from "@servicetitan/anvil2";

      function App() {
        return (
          <DateFieldYearlessRange
            label="Date Range"
            error="End date must be after start date"
            required
          />
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Sizes

    The component supports `small`, `medium`, and `large` sizes.

    <LiveCode showCode example="datefieldyearlessrange-size" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange, Flex } from "@servicetitan/anvil2";

      function App() {
        return (
          <Flex direction="column" gap="4" style={{ minWidth: "384px" }}>
            <DateFieldYearlessRange label="Small" size="small" />
            <DateFieldYearlessRange label="Medium" size="medium" />
            <DateFieldYearlessRange label="Large" size="large" />
          </Flex>
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Custom Labels

    Customize the accessible labels for the start and end date fields.

    <LiveCode showCode example="datefieldyearlessrange-label" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange } from "@servicetitan/anvil2";

      function App() {
        return (
          <DateFieldYearlessRange
            label="Service Period"
            startLabel="Service starts"
            endLabel="Service ends"
          />
        );
      }

      export default App;
      ```
    </LiveCode>

    ## React Accessibility

    * The component uses a `fieldset` with a `legend` for proper grouping
    * Start and end date fields have individual accessible labels (visually hidden)
    * Error messages are announced via `aria-live`
    * The `moreInfo` tooltip content is also available to screen readers

    For more guidance on form field labels and context, see [input field context association best practices](/docs/accessibility/labels-and-ctas#input-field-context-association).

    ### Markdown in labels

    The `label` prop supports inline markdown: bold (`**text**`), italic (`*text*`), bold and italic (`***text***`), highlight (`==text==`), and code (`` `text` ``).

    <LiveCode showCode example="datefieldyearlessrange-markdownlabel" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange, Flex } from "@servicetitan/anvil2";

      function App() {
        return (
          <Flex direction="column" gap="4" style={{ maxWidth: 500 }}>
            <DateFieldYearlessRange label="**Bold** label" />
            <DateFieldYearlessRange label="*Italic* label" />
            <DateFieldYearlessRange label="***Bold and italic*** label" />
            <DateFieldYearlessRange label="==Highlight== label" />
            <DateFieldYearlessRange label="`Code` label" />
          </Flex>
        );
      }

      export default App;
      ```
    </LiveCode>

    ### Hide the label

    Use `hideLabel` to visually hide the label. The `label` string is kept as a screen-reader-only `<legend>` element so the group remains accessible — any inline markdown is stripped to plain text.

    <LiveCode showCode example="datefieldyearlessrange-hidelabel" screenshot fullWidth>
      ```tsx lines expandable theme={null}
      import { DateFieldYearlessRange } from "@servicetitan/anvil2";

      function App() {
        return <DateFieldYearlessRange label="Service period" hideLabel />;
      }

      export default App;
      ```
    </LiveCode>
  </Tab>

  <Tab title="DateFieldYearlessRange Props">
    ```tsx theme={null}
    <DateFieldYearlessRange
      label="Date Range"
      mode="mm/dd"
      value={{ startDate: { month: 6, day: 1 }, endDate: { month: 8, day: 31 } }}
      onChange={(change) => console.log(change)}
      required={false}
      error={false}
      size="medium"
    />
    ```

    ## `DateFieldYearlessRange` Props

    The `DateFieldYearlessRange` component accepts the following props as well as layout utility props.

    <ParamField path="label" type="string" required>
      Label for the field. Supports inline markdown formatting.
    </ParamField>

    <ParamField path="defaultValue" type="DateFieldYearlessRangeValue">
      Default value for uncontrolled usage. Object with `startDate` and `endDate` properties, each containing `month` and `day` numbers.
    </ParamField>

    <ParamField path="description" type="ReactElement | string">
      Helper text displayed below the input.
    </ParamField>

    <ParamField path="disabled" type="boolean">
      Whether the field is disabled.
    </ParamField>

    <ParamField path="disableHint" type="boolean">
      Whether to hide the format hint (e.g., "Format: mm/dd").
    </ParamField>

    <ParamField path="disablePicker" type="boolean">
      Whether to disable the date picker popup.
    </ParamField>

    <ParamField path="endLabel" type="string" default="End date">
      Accessible label for the end date input (visually hidden).
    </ParamField>

    <ParamField path="error" type="ReactElement | string | boolean">
      Error message or error state for the field.
    </ParamField>

    <ParamField path="errorAriaLive" type={`"off" | "polite" | "assertive"`} default="assertive">
      The `aria-live` value for error messages.
    </ParamField>

    <ParamField path="hideLabel" type="boolean" default="false">
      Visually hides the label while keeping it accessible to screen readers.
    </ParamField>

    <ParamField path="id" type="string">
      Custom ID for the field.
    </ParamField>

    <ParamField path="legendProps" type={`Omit<FieldLabelProps, "el">`}>
      Additional props to pass to the legend [FieldLabel](/docs/web/components/field-label/code) component. Supports the `aiMark` prop for displaying [AI-powered field indicators](/docs/web/utilities/ai-marks).
    </ParamField>

    <ParamField path="mode" type={`"mm/dd" | "dd/mm"`} default="mm/dd">
      The date format mode.
    </ParamField>

    <ParamField path="moreInfo" type="ReactNode">
      Additional information to display in a tooltip next to the label.
    </ParamField>

    <ParamField path="onBlur" type="(event: React.FocusEvent) => void">
      Callback when the field loses focus.
    </ParamField>

    <ParamField path="onChange" type="(change: DateFieldYearlessRangeChange) => void">
      Callback when the date range value changes.
    </ParamField>

    <ParamField path="onFocus" type="(event: React.FocusEvent) => void">
      Callback when the field receives focus.
    </ParamField>

    <ParamField path="required" type="boolean">
      Whether the field is required.
    </ParamField>

    <ParamField path="size" type={`"small" | "medium" | "large"`}>
      The size of the input fields.
    </ParamField>

    <ParamField path="startLabel" type="string" default="Start date">
      Accessible label for the start date input (visually hidden).
    </ParamField>

    <ParamField path="value" type="DateFieldYearlessRangeValue">
      Controlled value. Object with `startDate` and `endDate` properties, each containing `month` and `day` numbers or `null`.
    </ParamField>

    ### Types

    ```tsx theme={null}
    type YearlessDate = {
      month: number; // 1-12
      day: number;   // 1-31
    };

    type DateFieldYearlessRangeValue = {
      startDate: YearlessDate | null;
      endDate: YearlessDate | null;
    };

    type DateFieldYearlessRangeChange = {
      startDate: YearlessDate | null;
      endDate: YearlessDate | null;
    };
    ```
  </Tab>
</Tabs>
