Material-ui: Re-export the ReferenceObject type of popper.js with the Popper component

Created on 25 May 2020  路  5Comments  路  Source: mui-org/material-ui

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Summary 馃挕

Should be able to import the ReferenceObject interface from material-ui instead of popper.js.

Examples 馃寛

Current way:

import { ReferenceObject } from 'popper.js'
import { Popper } from '@material-ui/core'

export default function ExamplePopperWrapper({
  anchorEl
}: {
  anchorEl: ReferenceObject
}) {
  return <Popper anchorEl={anchorEl} />
}

Proposed way:

import { Popper, PopperReferenceObject } from '@material-ui/core'

export default function ExamplePopperWrapper({
  anchorEl
}: {
  anchorEl: PopperReferenceObject
}) {
  return <Popper anchorEl={anchorEl} />
}

I don't know where it should be exported from, but somewhere in the material-ui core package. Otherwise, the abstraction is broken.

Motivation 馃敠

Typing my code properly without breaking abstraction or adding dependencies that are not directly used.

Thanks :)

Popper typescript

Most helpful comment

Something like

import Popper, { PopperProps } from '@material-ui/core/Popper'

export default function ExamplePopperWrapper({
  anchorEl
}: {
  anchorEl: NonNullable<PopperProps['anchorEl']>
}) {
  return <Popper anchorEl={anchorEl} />
}

All 5 comments

Would NonNullable<PopperProps['anchorEl']> work as well?

@eps1lon I'm not sure what you mean, sorry

Something like

import Popper, { PopperProps } from '@material-ui/core/Popper'

export default function ExamplePopperWrapper({
  anchorEl
}: {
  anchorEl: NonNullable<PopperProps['anchorEl']>
}) {
  return <Popper anchorEl={anchorEl} />
}

@eps1lon's approach sounds perfect, @DaniGuardiola let us know if you face any limitations with it.

@eps1lon perfect, I haven't had the chance to use it yet (been rewriting most of my project), but I'll let you know if I face any limitations. Looks good though. Thank you! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mb-copart picture mb-copart  路  3Comments

ghost picture ghost  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

revskill10 picture revskill10  路  3Comments

zabojad picture zabojad  路  3Comments