最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open MediaUpload from external component in Gutenberg

programmeradmin1浏览0评论

Gutenberg has MediaUpload component that allows selecting images from media library (its docs).

It allows to pass button to a render property, for example:

<MediaUpload
  onSelect={ ( media ) => console.log( 'selected ' + media.length ) }
  allowedTypes={ ALLOWED_MEDIA_TYPES }
  value={ mediaId }
  render={ ( { open } ) => (
    <Button onClick={ open }>
      Open Media Library
    </Button>
  ) }
/>

But I also have another component (outside of the render function), doubleclick on it should open the same media library.

<AnotherComponent 
  ondoubleclick={ /* how do I open the same media modal here? */ }
></AnotherComponent>

Is there some way to do it with a single <MediaUpload/> component, or I need multiple?

发布评论

评论列表(0)

  1. 暂无评论