{"id":390,"date":"2021-01-27T11:50:29","date_gmt":"2021-01-27T11:50:29","guid":{"rendered":"https:\/\/codeamp.com\/?p=390"},"modified":"2024-03-03T11:56:41","modified_gmt":"2024-03-03T11:56:41","slug":"a-gutenberg-multiselect-component","status":"publish","type":"post","link":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/","title":{"rendered":"A Gutenberg MultiSelect component"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"277\" height=\"161\" src=\"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif\" alt=\"\" class=\"wp-image-391\"\/><\/figure>\n\n\n\n<p>This is a little adaptation of the <code>FormTokenField<\/code> found in Gutenberg core.<\/p>\n\n\n\n<p>Working on the <a href=\"https:\/\/wordpress.org\/plugins\/custom-layouts\/\" target=\"_blank\" rel=\"noreferrer noopener\">Custom Layouts<\/a> plugin, I needed a multiselect for it&#8217;s layout block and editor options.<\/p>\n\n\n\n<p>There are some cool controls already in Gutenberg for selecting a page, or choosing tags, but they are not actual multiselect &#8211; that is, a set of options presented to the user to choose from, and the ability to select multiple (this is just my opinion, not definition&#8230;).<\/p>\n\n\n\n<p>The existing compontents require search\/input before displaying options, whereas I wanted to show all options on interaction.  While I can see <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/1044\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">it is not planned<\/a> to add this into the current components system, I think it will be covered by<a href=\"https:\/\/g2-components.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"> G2 Components<\/a> &#8211; so consider this a filler, until that time.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/rmorse\/wp-token-multiselect-control\" target=\"_blank\" rel=\"noreferrer noopener\">You can get the source code here.<\/a><\/p>\n\n\n\n<p>I hope you will find it handy &#8211; happy coding <em>(and hurry up G2, thanks&#8230;)<\/em><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a little adaptation of the FormTokenField found in Gutenberg core. Working on the Custom Layouts plugin, I needed a multiselect for it&#8217;s layout block and editor options. There are some cool controls already in Gutenberg for selecting a page, or choosing tags, but they are not actual multiselect &#8211; that is, a set [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,11,7],"tags":[],"class_list":["post-390","post","type-post","status-publish","format-standard","hentry","category-gutenberg","category-plugins","category-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A Gutenberg MultiSelect component - Code Amp<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A Gutenberg MultiSelect component - Code Amp\" \/>\n<meta property=\"og:description\" content=\"This is a little adaptation of the FormTokenField found in Gutenberg core. Working on the Custom Layouts plugin, I needed a multiselect for it&#8217;s layout block and editor options. There are some cool controls already in Gutenberg for selecting a page, or choosing tags, but they are not actual multiselect &#8211; that is, a set [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Amp\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-27T11:50:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-03T11:56:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif\" \/>\n<meta name=\"author\" content=\"Ross Morsali\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rmors_\" \/>\n<meta name=\"twitter:site\" content=\"@code_amp\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ross Morsali\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/\"},\"author\":{\"name\":\"Ross Morsali\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/person\\\/f07e5a501a3e476f253174c4f8085e64\"},\"headline\":\"A Gutenberg MultiSelect component\",\"datePublished\":\"2021-01-27T11:50:29+00:00\",\"dateModified\":\"2024-03-03T11:56:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/\"},\"wordCount\":154,\"publisher\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/token-multi-select-control.gif\",\"articleSection\":[\"Gutenberg\",\"Plugins\",\"WordPress\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/\",\"url\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/\",\"name\":\"A Gutenberg MultiSelect component - Code Amp\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/token-multi-select-control.gif\",\"datePublished\":\"2021-01-27T11:50:29+00:00\",\"dateModified\":\"2024-03-03T11:56:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#primaryimage\",\"url\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/token-multi-select-control.gif\",\"contentUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/token-multi-select-control.gif\",\"width\":277,\"height\":161},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/a-gutenberg-multiselect-component\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codeamp.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A Gutenberg MultiSelect component\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#website\",\"url\":\"https:\\\/\\\/codeamp.com\\\/\",\"name\":\"Code Amp\",\"description\":\"Developing WordPress Plugins\",\"publisher\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codeamp.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#organization\",\"name\":\"Code Amp\",\"url\":\"https:\\\/\\\/codeamp.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/codeampsquare.png\",\"contentUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/codeampsquare.png\",\"width\":500,\"height\":500,\"caption\":\"Code Amp\"},\"image\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/code_amp\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/person\\\/f07e5a501a3e476f253174c4f8085e64\",\"name\":\"Ross Morsali\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g\",\"caption\":\"Ross Morsali\"},\"description\":\"Web developer by trade, with over 15 years building things in PHP, HTML, CSS, and JavaScript - focusing on WordPress for the last 7 years.\",\"sameAs\":[\"https:\\\/\\\/codeamp.com\",\"https:\\\/\\\/x.com\\\/rmors_\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A Gutenberg MultiSelect component - Code Amp","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/","og_locale":"en_GB","og_type":"article","og_title":"A Gutenberg MultiSelect component - Code Amp","og_description":"This is a little adaptation of the FormTokenField found in Gutenberg core. Working on the Custom Layouts plugin, I needed a multiselect for it&#8217;s layout block and editor options. There are some cool controls already in Gutenberg for selecting a page, or choosing tags, but they are not actual multiselect &#8211; that is, a set [&hellip;]","og_url":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/","og_site_name":"Code Amp","article_published_time":"2021-01-27T11:50:29+00:00","article_modified_time":"2024-03-03T11:56:41+00:00","og_image":[{"url":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif","type":"","width":"","height":""}],"author":"Ross Morsali","twitter_card":"summary_large_image","twitter_creator":"@rmors_","twitter_site":"@code_amp","twitter_misc":{"Written by":"Ross Morsali","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#article","isPartOf":{"@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/"},"author":{"name":"Ross Morsali","@id":"https:\/\/codeamp.com\/#\/schema\/person\/f07e5a501a3e476f253174c4f8085e64"},"headline":"A Gutenberg MultiSelect component","datePublished":"2021-01-27T11:50:29+00:00","dateModified":"2024-03-03T11:56:41+00:00","mainEntityOfPage":{"@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/"},"wordCount":154,"publisher":{"@id":"https:\/\/codeamp.com\/#organization"},"image":{"@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#primaryimage"},"thumbnailUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif","articleSection":["Gutenberg","Plugins","WordPress"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/","url":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/","name":"A Gutenberg MultiSelect component - Code Amp","isPartOf":{"@id":"https:\/\/codeamp.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#primaryimage"},"image":{"@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#primaryimage"},"thumbnailUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif","datePublished":"2021-01-27T11:50:29+00:00","dateModified":"2024-03-03T11:56:41+00:00","breadcrumb":{"@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#primaryimage","url":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif","contentUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/token-multi-select-control.gif","width":277,"height":161},{"@type":"BreadcrumbList","@id":"https:\/\/codeamp.com\/a-gutenberg-multiselect-component\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codeamp.com\/"},{"@type":"ListItem","position":2,"name":"A Gutenberg MultiSelect component"}]},{"@type":"WebSite","@id":"https:\/\/codeamp.com\/#website","url":"https:\/\/codeamp.com\/","name":"Code Amp","description":"Developing WordPress Plugins","publisher":{"@id":"https:\/\/codeamp.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codeamp.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/codeamp.com\/#organization","name":"Code Amp","url":"https:\/\/codeamp.com\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/codeamp.com\/#\/schema\/logo\/image\/","url":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/codeampsquare.png","contentUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/codeampsquare.png","width":500,"height":500,"caption":"Code Amp"},"image":{"@id":"https:\/\/codeamp.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/code_amp"]},{"@type":"Person","@id":"https:\/\/codeamp.com\/#\/schema\/person\/f07e5a501a3e476f253174c4f8085e64","name":"Ross Morsali","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g","caption":"Ross Morsali"},"description":"Web developer by trade, with over 15 years building things in PHP, HTML, CSS, and JavaScript - focusing on WordPress for the last 7 years.","sameAs":["https:\/\/codeamp.com","https:\/\/x.com\/rmors_"]}]}},"_links":{"self":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/posts\/390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/comments?post=390"}],"version-history":[{"count":0,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/posts\/390\/revisions"}],"wp:attachment":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/media?parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/categories?post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/tags?post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}