Skip to content

[material-ui][FocusTrap] getTabbable function has a return type of string[] instead of HTMLElement[] #42231

@KalmarLorand

Description

@KalmarLorand

Steps to reproduce

Link to live example: (required)

Steps:

  1. Create a Focustrap component
  2. Pass in the getTabbable function that returns an array of nodes Returns an array of ordered tabbable nodes
  3. Notice the Typescript Linting error.

Current behavior

Based on the description of the getTabbable prop of the FocusTrap component:
Returns an array of ordered tabbable nodes (i.e. in tab order) within the root. For instance, you can provide the "tabbable" npm dependency.
However, the type definition of this function expects it to return a ReadonlyArray<string>.
When returning a HTML Element array, it throws:

Type '(root: HTMLElement) => HTMLAnchorElement[]' is not assignable to type '(root: HTMLElement) => readonly string[]'.
  Type 'HTMLAnchorElement[]' is not assignable to type 'readonly string[]'.
    Type 'HTMLAnchorElement' is not assignable to type 'string'.typescript(2322)
FocusTrap.types.d.ts(12, 5): The expected type comes from property 'getTabbable' which is declared here on type 'IntrinsicAttributes & Pick<FocusTrapProps, keyof FocusTrapProps> & Pick<InferProps<any>, string | number | symbol> & Pick<...>'

Expected behavior

The getTabbable prop should accept a function returning an array of HTMLElements.

Search keywords: getTabbable, FocusTrap

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGreat for first contributions. Enable to learn the contribution process.scope: focus trapChanges related to the focus trap.type: bugIt doesn't behave as expected.typescript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions