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:
Still experimental, and doesn’t fit in the sidebar:
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.
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
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