volto icon indicating copy to clipboard operation
volto copied to clipboard

TextWidget: Pass onChange in iconAction

Open mcasagrande18 opened this issue 3 years ago • 1 comments

It would be useful to have access to onChange function in iconAction, for exemple to implement clear action.

iconAction function ex:

<TextWidget
  ...
  iconAction={(e, id, onChange) => {
    e.target.value = '';
    onChange(id, undefined);
  }}
/>

mcasagrande18 avatar May 18 '22 08:05 mcasagrande18

@mcasagrande18

You can still do it, given the schema property, and access to the props:

      url: {
        title: intl.formatMessage(messages.image),
        value: imageUrl,
        icon: props.data.url ? clearSVG : navTreeSVG,
        iconAction: props.data.url
          ? () => {
              props.resetSubmitUrl();
              props.onChangeBlock(props.block, {
                ...props.data,
                url: '',
              });
            }
          : () =>
              props.openObjectBrowser({
                onSelectItem: props.onSelectItem,
              }),
      },

sneridagh avatar Sep 27 '22 10:09 sneridagh