2

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:

enter image description here

or toolbar:

enter image description here

URLInputButton / UrlInput

Doesn't fit in the sidebar or toolbar:

enter image description here

and the dropdown isn't happy in any case:

enter image description here

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.