Skip to content

incorrect UI change and defaultValue does not work when value is null #912

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

Closed
electroluxcode opened this issue Feb 26, 2025 · 1 comment · Fixed by #913
Closed

incorrect UI change and defaultValue does not work when value is null #912

electroluxcode opened this issue Feb 26, 2025 · 1 comment · Fixed by #913

Comments

@electroluxcode
Copy link
Contributor

electroluxcode commented Feb 26, 2025

Expected Behavior

  • The UI should correctly reflect changes when interacting with the Picker. it is no work right now
  • defaultValue should be applied when value is null.

Link

https://codesandbox.io/p/devbox/rc-picker-playground-forked-3nhyt2?workspaceId=ws_3QLa1fC9z31NSTkNNrEQtj

code

import moment, { Moment } from "moment";
import * as React from "react";
import Picker from "rc-picker";
import "rc-picker/assets/index.css";

import generateConfig from "./generateMoment";
import { locale } from "./zh_cn";
export default function App() {
  const defaultvalue = moment("2023-06-01");
  return (
    <>
      <div>
        <Picker<Moment>
          generateConfig={generateConfig}
          locale={locale}
          defaultValue={defaultvalue}
          value={undefined}
        />
      </div>
      <div>
        defaultValue no work
        <Picker<Moment>
          generateConfig={generateConfig}
          locale={locale}
          value={null}
          defaultValue={defaultvalue}
          showTime={{
            showSecond: false,
          }}
        />
      </div>

      <div>
        ui no work
        <Picker<Moment>
          generateConfig={generateConfig}
          locale={locale}
          value={null}
          showTime={{
            showSecond: false,
          }}
        />
      </div>
    </>
  );
}
@zombieJ
Copy link
Member

zombieJ commented Mar 26, 2025

Sorry for delay. value={null} means you control the value to be null which is match with clear operation. It's by design and not a bug. I will revert pr #913. For uncontrolled should use undefined instead of null. If your case need trade null as same behavior as undefined, pls HOC picker instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants