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

FileButton Reset - Suggestion to Safely Handle inputRef Reset #7025

Closed
1 task done
jsonchou opened this issue Oct 24, 2024 · 1 comment
Closed
1 task done

FileButton Reset - Suggestion to Safely Handle inputRef Reset #7025

jsonchou opened this issue Oct 24, 2024 · 1 comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@jsonchou
Copy link

jsonchou commented Oct 24, 2024

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?

7.13.2

What package has an issue?

@mantine/core

What framework do you use?

Next.js

In which browsers you can reproduce the issue?

Chrome

Describe the bug

When using the following logic in tsx:

  const handleReset = () => {
    setFile(null)
    setImageSrc('')
    if (resetRef?.current) {
      resetRef.current?.()
    }
  }

{imageSrc ? (
  <Group pos={"relative"}>
    <Image src={imageSrc} w={36} h={36} radius={"xs"} />
    <ActionIcon variant="outline" size={'xs'} pos={'absolute'} onClick={handleReset}>
      <IconX size={12} />
    </ActionIcon>
  </Group>
) : (
  <FileButton resetRef={resetRef}>
    {(props) => (
      <ActionIcon {...props} onClick={handleUpload}>
        <IconPhoto size={24} />
      </ActionIcon>
    )}
  </FileButton>
)}

The following error is thrown when resetting the input, and handleReset have no way to skip it:

TypeError: Cannot set properties of null (setting 'value')

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

No response

Possible fix

Modify the logic within the FileButton component to safely reset the input value only when inputRef is not null. The following code modification has been tested locally and resolves the issue:

if (inputRef?.current) {
  inputRef.current.value = "";
}

It looks like a simple and safe snippet of code.


### Self-service

- [X] I would be willing to implement a fix for this issue
rtivital added a commit that referenced this issue Nov 7, 2024
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Nov 7, 2024
@rtivital
Copy link
Member

rtivital commented Nov 8, 2024

Fixed in 7.13.5

@rtivital rtivital closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants