[Issue]
Will get the console error as below when all the following 3 conditions are true.
"onGetTokenErrorMessage" is required when "ErrorType" not "string"
ErrorType is neither string nor Nullish
Do not provide prop onGetTokenErrorMessage
Apply the built-in Token component
However, the user of TokenInput could make their own error look & feel into the built-in Token component via onGetTokenDisplayLabel without applying onGetTokenErrorMessage.
In this case, the onGetTokenErrorMessage will be meaning less to provide. The user will need to make a dummy onGetTokenErrorMessage (return undefined [1]) to bypass the console error.
[1] The built-in Token component will apply the string type return value of onGetTokenErrorMessage as the title attribute
[Example code]
const handleTokenValueValidate = (tokenValue) => {
const num = parseInt(tokenValue, 10);
if (Number.isNaN(num) === true) {
return new Error('Input value is not a number');
}
return null;
};
const handleGetTokenDisplayLabel = (tokenValue, tokenMeta) => {
const { error } = tokenMeta;
if (error instanceof Error) {
return `${tokenValue} with error: ${error.message}`;
}
return `${tokenValue}`;
};
const ExampleDefault = () => {
const [values, setValues] = useState([]);
return (
<TokenInput
tokenValues={values}
onTokenValuesChange={setValues}
onGetTokenDisplayLabel={handleGetTokenDisplayLabel}
onTokenValueValidate={handleTokenValueValidate}
// provide to avoid rise Error
// onGetTokenErrorMessage={() => undefined}
/>
);
};
[Impact versions] Since v2.0.0
[Issue] Will get the console error as below when all the following 3 conditions are true.
ErrorType
is neitherstring
norNullish
onGetTokenErrorMessage
However, the user of TokenInput could make their own error look & feel into the built-in Token component via
onGetTokenDisplayLabel
without applyingonGetTokenErrorMessage
. In this case, theonGetTokenErrorMessage
will be meaning less to provide. The user will need to make a dummy onGetTokenErrorMessage (returnundefined
[1]) to bypass the console error.[1] The built-in Token component will apply the
string type
return value of onGetTokenErrorMessage as thetitle
attribute[Example code]