Write the code for this React component: function VisuallyHidden( { text, as: Tag =…
- User
Write the code for this React component: function VisuallyHidden( { text, as: Tag = 'span', noTranslate = false, additionalAttributes = {}, } ) It returns an element text: The innerText of the element Tag: the html tag of the element noTranslate: determines if the element has the attribute data-notranslate="true" additionalAttributes: All other attributes passed into the element
- Assistant
Here is the code for the VisuallyHidden React component:
import React from 'react';
function VisuallyHidden({ text, as: Tag = 'span', noTranslate = false, additionalAttributes = {}, }) { const translateAttr = noTranslate ? { 'data-notranslate': 'true' } : {};
return ( <Tag {...additionalAttributes} {...translateAttr} style={{ position: 'absolute', clip: 'rect(0 0 0 0)', width: 1, height: 1, margin: -1, padding: 0, border: 0, overflow: 'hidden', whiteSpace: 'nowrap' }}> {text} ); }
export default VisuallyHidden;
This component uses the spread operator to pass all additional attributes into the element, and sets the style properties to make the element visually hidden while still allowing it to be read by screen readers. The noTranslate prop is used to conditionally add the data-notranslate attribute to the element.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.