import { Components } from '@formio/js';
const TextArea = Components.components.textarea;
// A read-only textarea renders as `
` with no accessible name.
export default class GDSTextArea extends TextArea {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public renderElement(value: any, index: any): string {
const html: string = super.renderElement(value, index);
const label = this.component.label;
if (!label || typeof html !== 'string' || !html.includes('role="textbox"') || /\baria-label\s*=/.test(html)) {
return html;
}
const name = (this as unknown as { getFormattedAttribute: (v: string) => string }).getFormattedAttribute(
this.t(label),
);
return html.replace('role="textbox"', `role="textbox" aria-label="${name}"`);
}
}