')
.addRegularText('was not provided')
.printMessage();
}
}
/**
* Watch for changes to the `caption` prop.
*
* The caption will be run through the InputCaption constructor to convert it to the correct format, and set the result to the `captionState` state.
* @param newValue: Caption | string
*/
@Watch('caption')
private updateCaptionState(newValue: Caption | string) {
this.captionState = new InputCaption(
this.element.tagName,
newValue,
translations,
this.language,
false,
this.required,
);
}
/**
* Watch for changes to the `language` prop to render either the English or French translations
*/
@Watch('language')
updateLanguage() {
this.updateCaptionState(this.caption);
}
@Watch('errorMessage')
broadcastInputErrorOccurredEvent() {
// Emit event to notify anyone who wants to listen for errors occurring
this.inputErrorOccurred.emit({ inputId: this.getId(), errorMessage: this.errorMessage ?? '' });
}
/**
* Function to handle textarea events and the information pertaining to the textarea to emit.
*/
private handleEvent(event: Event, eventType: EventType) {
const input = event.target as HTMLTextAreaElement | null;
this.value = input?.value;
// Guard usage of `this.internals` to ensure this logic only runs in the browser.
// `ElementInternals` is not available during SSR, and unguarded access can cause hydration errors.
if (typeof this.internals?.setFormValue === 'function') {
this.internals.setFormValue(this.value ?? '');
}
handleInputEvent(
event,
eventType,
input,
this.inputOnChange,
this.inputOnFocus,
this.inputOnBlur,
this.inputOnInput,
'input',
this.customOnChange,
this.customOnFocus,
this.customOnBlur,
this.customOnInput,
this.element,
);
}
public getId(): string {
return this.elementId ?? '';
}
private getValue(): string | number {
return this.value ?? '';
}
private getClass(): string {
return this.hintExpander ? `ontario-textarea ontario-textarea-hint-expander--true` : `ontario-textarea`;
}
/**
* If a `hintText` prop is passed, the id generated from it will be set to the internal `hintTextId` state to match with the textarea `aria-describedBy` attribute.
*/
async componentDidLoad() {
this.hintTextId = await this.hintTextRef?.getHintTextId();
}
componentWillLoad() {
this.updateCaptionState(this.caption);
this.elementId = this.elementId ?? uuid();
this.parseHintText();
this.parseHintExpander();
this.validateName(this.name);
this.language = validateLanguage(this.language);
}
render() {
const error = !!this.errorMessage;
return (
{this.captionState.getCaption(this.getId(), !!this.internalHintExpander)}
{this.internalHintText && (
(this.hintTextRef = el)}
>
)}
{this.internalHintExpander && (
)}
);
}
}