Skip to content

feat(ui-filedrop): add inputRef prop to make FileDrop focusable#1853

Merged
joyenjoyer merged 1 commit intomasterfrom
INSTUI-4431_allow_focusing_file_drop_programatically
Feb 3, 2025
Merged

feat(ui-filedrop): add inputRef prop to make FileDrop focusable#1853
joyenjoyer merged 1 commit intomasterfrom
INSTUI-4431_allow_focusing_file_drop_programatically

Conversation

@ToMESSKa
Copy link
Contributor

@ToMESSKa ToMESSKa commented Jan 30, 2025

Closes: INSTUI-4431

ISSUE: Filedrop input cannot be focused, it needs a inputRef prop like Select or TextInput

TEST PLAN:

  • test the example below in the documentation preview
  • fileDrop should accept inputRef prop
  • by clicking on the Focus File Input button, the FileDrop should receive focus
  • review the updated documentation and new tests
class Example extends React.Component {
  fileInputElement = null

  focusFileInput = () => {
    if (this.fileInputElement) {
      this.fileInputElement.focus()
    }
  };

  render() {
    return (
      <div>
        <FileDrop
          accept="image/*"
          onDropAccepted={([file]) => console.log(`File accepted ${file.name}`)}
          onDropRejected={([file]) => console.log(`File rejected ${file.name}`)}
          inputRef={(el) => {
            this.fileInputElement = el;
          }}
          renderLabel={
            <View as="div" padding="xx-large large" background="primary">
              <IconModuleLine size="large" />
              <Heading>Drop files here to add them to module</Heading>
              <Text color="brand">
                Drag and drop, or click to browse your computer
              </Text>
            </View>
          }
        />
        <button onClick={this.focusFileInput}>Focus File Input</button>
      </div>
    );
  }
}
render(<Example />)

@ToMESSKa ToMESSKa self-assigned this Jan 30, 2025
@github-actions
Copy link

github-actions bot commented Jan 30, 2025

PR Preview Action v1.6.0
Preview removed because the pull request was closed.
2025-02-03 12:30 UTC

Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

Copy link
Contributor

@joyenjoyer joyenjoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work Tamas

@joyenjoyer joyenjoyer merged commit a3a75e0 into master Feb 3, 2025
8 checks passed
@joyenjoyer joyenjoyer deleted the INSTUI-4431_allow_focusing_file_drop_programatically branch February 3, 2025 12:29
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 this pull request may close these issues.

3 participants