Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jfulse opened this issue Feb 11, 2022 · 2 comments
Open
Labels
bug Something isn't working

Comments

@jfulse
Copy link

jfulse commented Feb 11, 2022

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

@SimeonGriggs
Copy link

This appears to be an issue with Safari itself, where an input with type="time" will render 12:30 as placeholder text when the field is empty.

Here's a reproduction in Sanity UI

It could be possible for Sanity UI to overwrite this default.

@danmichaelo
Copy link

danmichaelo commented May 3, 2022

You’re right, this seems to be a Safari issue at its heart! Yet it’s made worse by the fact that there’s no visual difference between the placeholder value and an actual value with the Sanity UI styling (with no styling, "12:30" is shown in grey, changing to black when you enter a value). Didn’t find much discussion about it, but seems like a fix will have to be rather hacky 😞 https://stackoverflow.com/questions/69919586/how-to-remove-the-default-time-1230-pm-in-desktop-safari

@RitaDias RitaDias added the bug Something isn't working label Dec 16, 2022
@kmelve kmelve transferred this issue from sanity-io/sanity Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants