Skip to content

TimePicker doesn’t reflect external update after being cleared with an empty string #8108

@lambdalisue

Description

@lambdalisue

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

8.2.0

What package has an issue?

@mantine/dates

What framework do you use?

React Router

In which browsers you can reproduce the issue?

Chrome

Describe the bug

When an empty string is passed to the TimePicker as its value, the next external update (for example, setting "12:00") does not appear in the DOM. The change is only reflected after a second update is applied.

A video demonstrating the issue:

CleanShot.2025-07-24.at.18.47.30.mp4
import { useState } from "react";
import { Stack, Button, Center } from "@mantine/core";
import { TimePicker } from "@mantine/dates";

type Time = { hour: number; minute: number };

function fromString(timeString: string): Time {
  const [hour, minute] = timeString.split(":").map(Number);
  return { hour, minute };
}

function intoString(time: Time): string {
  return `${String(time.hour).padStart(2, "0")}:${String(time.minute).padStart(2, "0")}`;
}

export default function Home() {
  const [time, setTime] = useState<Time | null>(null);

  const handleTimeChange = (value: string) => {
    setTime(value ? fromString(value) : null);
  };

  return (
    <Center w="100%" h="100%">
      <Stack>
        <TimePicker
          value={time ? intoString(time) : ""}
          onChange={handleTimeChange}
          withDropdown
        />
        <pre>Time: {JSON.stringify(time, null, 2)}</pre>
        <Button onClick={() => setTime({ hour: 12, minute: 0 })}>
          Set to 12:00
        </Button>
        <Button onClick={() => setTime({ hour: 10, minute: 0 })}>
          Set to 10:00
        </Button>
        <Button onClick={() => setTime(null)}>Clear</Button>
      </Stack>
    </Center>
  );
}

I found this related issue, but the behavior seems different. Am I overlooking something, or is this a separate bug?

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

No response

Self-service

  • I would be willing to implement a fix for this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedCompleted issues that will be published with next patch (1.0.X)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions