Skip to content

TextInputs from @sanity/ui with type=time don't work properly in Safari #1046

@jfulse

Description

@jfulse

Describe the bug

There is a problem when clearing the time input using backspace. In Safari the old value still persists in the DOM, even on refresh, even though it's no longer present in the dataset (I presume it's stored in the revisions somewhere?)

The input works normally in other browsers. I haven't been able to find anything about this so I assume it's a problem with Sanity, could be wrong of course.

To Reproduce

Minimal schema:

// exampleDocumentType.js
import TimeInput from "../inputComponents/TimeInput";

export default {
  name: "exampleDocumentType",
  title: "Example document type",
  type: "document",
  fields: [
    {
      name: "title",
      title: "Title",
      type: "string",
    },
    {
      name: "time",
      title: "Time",
      type: "string",
      inputComponent: TimeInput,
    },
  ],
};

// schema.js
import createSchema from "part:@sanity/base/schema-creator";
import schemaTypes from "all:part:@sanity/base/schema-type";
import exampleDocumentType from "./exampleDocumentType";

export default createSchema({
  name: "default",
  types: schemaTypes.concat([exampleDocumentType]),
});

Minimal input component:

// inputComponents/TimeInput.js
import React, { forwardRef } from "react";
import { TextInput } from "@sanity/ui";
import PatchEvent, { set, unset } from "@sanity/form-builder/PatchEvent";

const TimeInput = (props, forwardedRef) => {
  const handleChange = ({ target }) =>
    props.onChange(PatchEvent.from(set(target.value ?? "")));

  return (
    <TextInput
      type="time"
      value={props.value}
      onChange={handleChange}
      ref={forwardedRef}
      readOnly={props.readOnly}
      onFocus={props.onFocus}
      onBlur={props.onBlur}
    />
  );
};

export default forwardRef(TimeInput);

Expected behavior

The time input should be empty when there is no value

Screenshots

Deleted value on safari:
Skjermbilde 2022-02-11 kl  16 48 26

On Firefox:
Skjermbilde 2022-02-11 kl  16 48 33

Which versions of Sanity are you using?

@sanity/cli 2.19.1 (latest: 2.27.0)
@sanity/base 2.27.0 (up to date)
@sanity/core 2.27.0 (up to date)
@sanity/default-layout 2.27.0 (up to date)
@sanity/default-login 2.27.0 (up to date)
@sanity/desk-tool 2.27.0 (up to date)
@sanity/eslint-config-studio 2.0.0 (up to date)
@sanity/vision 2.27.0 (up to date)

What operating system are you using?

macOS Big Sur

Which versions of Node.js / npm are you running?

7.24.2
v16.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions