Gutenberg: HierarchicalTermSelector and FlatTermSelector are not reusable

Created on 19 Sep 2019  路  3Comments  路  Source: WordPress/gutenberg

It doesn't seem like HierarchicalTermSelector and FlatTermSelector can be accessed from a plugin, so they can't be reused.

I'd like be to able to do something like:

import HierarchicalTermSelector from '@wordpress/editor';

function customizeTaxonomySelector( OriginalComponent ) {
    return function( props ) {
        if ( 'my_taxonomy' !== props.slug ) {
            return <OriginalComponent { ...props } />;
        }

        return <HierarchicalTermSelector { ...props } />;
    };
}
wp.hooks.addFilter( 'editor.PostTaxonomyType', 'my-custom-plugin', customizeTaxonomySelector );

My use case is https://github.com/WordPress/gutenberg/issues/13816#issuecomment-532885577, where I want to use the hierarchical term selector w/ a flat taxonomy, because it's a better UX for that specific taxonomy.

Possibly related #2761

[Feature] Extensibility [Package] Editor [Type] Enhancement

Most helpful comment

Any updates on this? Almost every website we make requires a flat taxonomy to be shown as checkboxes, or that only allows a single selection (radio or dropdown). Extending HierarchicalTermSelector seems to be possible way to do this, aside from these options just being in core.

All 3 comments

That鈥檚 a valid use case to expose them. I didn鈥檛 anticipate it happening to be honest 馃槂

Any updates on this? Almost every website we make requires a flat taxonomy to be shown as checkboxes, or that only allows a single selection (radio or dropdown). Extending HierarchicalTermSelector seems to be possible way to do this, aside from these options just being in core.

Setting show_in_rest to true makes the taxonomy selection appear in Gutenberg editor.
However, the taxonomy selection field stays grey/disabled and a JavaScript error occurs:
Warning: Can't perform a React state update on an unmounted component.
Related: https://github.com/WordPress/gutenberg/issues/13517#issuecomment-708486733

Was this page helpful?
0 / 5 - 0 ratings