Skip to content

Commit

Permalink
fix(ui-file-drop): set aria-invalid to true when there are error mess…
Browse files Browse the repository at this point in the history
…ages

TEST PLAN:
Read a FileDrop with a screen reader. it should say the error message and 'invalid data'
  • Loading branch information
matyasf committed Jul 5, 2024
1 parent def7630 commit 67fce51
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/ui-file-drop/src/FileDrop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,25 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
return this.interaction === 'disabled' || this.interaction === 'readonly'
}

get hasMessages() {
return this.props.messages && this.props.messages.length > 0
}

get interaction() {
return getInteraction({ props: this.props })
}

get hasMessages() {
return this.props.messages ? this.props.messages.length > 0 : false
}

get invalid() {
return (this.hasMessages &&
this.props.messages!.findIndex((message: FormMessage) => {
return message.type === 'error'
}) >= 0) as boolean
if (this.hasMessages) {
return (
this.props.messages!.findIndex((message: FormMessage) => {
return message.type === 'error'
}) >= 0
)
}
return false
}

getDataTransferItems(
e: React.ChangeEvent | React.DragEvent,
shouldEnablePreview?: boolean
Expand Down Expand Up @@ -383,6 +388,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
accept={this.acceptStr()}
onChange={this.handleChange}
aria-describedby={this.hasMessages ? this.messagesId : undefined}
aria-invalid={this.invalid}
disabled={this.functionallyDisabled}
/>
{this.hasMessages ? (
Expand Down

0 comments on commit 67fce51

Please sign in to comment.