admin管理员组

文章数量:1292183

I have a custom block that needs a URL attribute. I figured it made sense to set the URL in the sidebar or the toolbar, but I can't find a way to do it. I've tried:

LinkControl

Still experimental, and doesn't fit in the sidebar:

or toolbar:

URLInputButton / UrlInput

Doesn't fit in the sidebar or toolbar:

and the dropdown isn't happy in any case:

Is there a recommended way to do this? I've looked at the image block, but that seems to use its own special implementation of LinkControl. The RichText block does it inline, which won't work for me. I'm sure I'm missing something obvious.

I have a custom block that needs a URL attribute. I figured it made sense to set the URL in the sidebar or the toolbar, but I can't find a way to do it. I've tried:

LinkControl

Still experimental, and doesn't fit in the sidebar:

or toolbar:

URLInputButton / UrlInput

Doesn't fit in the sidebar or toolbar:

and the dropdown isn't happy in any case:

Is there a recommended way to do this? I've looked at the image block, but that seems to use its own special implementation of LinkControl. The RichText block does it inline, which won't work for me. I'm sure I'm missing something obvious.

Share Improve this question asked May 27, 2021 at 15:21 Andrew WestAndrew West 1436 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

UrlInput uses LinkControl internally, but neither have been built with the sidebar in mind, they're to be used inside popover components that appear inline such as when a toolbar button is clicked.

They aren't intended to appear directly in toolbars either. Most if not all input components can't be shown in the toolbar, with the exception of buttons for obvious reasons.

If using this component causes overflow in the sidebar, then you need to report this as a bug in the Gutenberg Github issues as soon as possible so that it can be fixed.

Otherwise this is the closest you will find currently to a canonical post/URL selection input. I suggest for the moment that you print the URL value and show an edit button next to it that triggers a popover component containing the link control

本文标签: block editorWhat39s the recommended Gutenberg component for adding a URLin the toolbarsidebar