Skip to content

Commit

Permalink
Merge pull request #853 from gympass/feat/adjusts-accessibility-of-in…
Browse files Browse the repository at this point in the history
…put-component

Feat/adjusts accessibility of input component
  • Loading branch information
flavia-moraes authored Dec 10, 2024
2 parents 5c9b870 + 7971780 commit 01cd9be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/yoga/src/Input/web/Helper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Helper = ({
</Info>
)}
{maxLength && !hideMaxLength && (
<Info as="span">
<Info as="span" aria-hidden>
{length}/{maxLength}
</Info>
)}
Expand Down
6 changes: 5 additions & 1 deletion packages/yoga/src/Input/web/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const Input = React.forwardRef(
hideMaxLength,
rightIcon,
a11yId,
closeAriaLabel,
includeAriaAttributes,
leftElement,
...props
Expand Down Expand Up @@ -214,7 +215,7 @@ const Input = React.forwardRef(
role="button"
hasIconRight={!!rightIcon}
>
<Close aria-label="Clear" />
<Close aria-label={closeAriaLabel} />
</IconWrapper>
)}

Expand Down Expand Up @@ -274,6 +275,8 @@ Input.propTypes = {
a11yId: string,
/** useful for components that extend the Input component and have their own ARIA attributes implementation (e.g. Dropdown) */
includeAriaAttributes: bool,
/** this prop will be used in the aria-label of the clear input button. */
closeAriaLabel: string,

/** element on the left */
leftElement: node,
Expand All @@ -298,6 +301,7 @@ Input.defaultProps = {
placeholder: undefined,
rightIcon: undefined,
a11yId: undefined,
closeAriaLabel: 'Clear',
includeAriaAttributes: true,
leftElement: undefined,
};
Expand Down
17 changes: 16 additions & 1 deletion packages/yoga/src/Input/web/Password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ const IconWrapper = styled.div`
`}
`;

const Password = ({ disabled, style, className, full, ...props }) => {
const Password = ({
disabled,
style,
className,
full,
showPasswordAriaLabel,
hidePasswordAriaLabel,
...props
}) => {
const [showPassword, toggleShowPassword] = useState(false);
const inputRef = useRef(null);

Expand Down Expand Up @@ -120,6 +128,9 @@ const Password = ({ disabled, style, className, full, ...props }) => {
onKeyDown={togglePassword}
disabled={disabled}
role="button"
aria-label={
showPassword ? showPasswordAriaLabel : hidePasswordAriaLabel
}
>
{showPassword ? (
<Visibility width={20} height={20} />
Expand All @@ -135,6 +146,8 @@ Password.propTypes = {
className: string,
disabled: bool,
full: bool,
showPasswordAriaLabel: string,
hidePasswordAriaLabel: string,
style: shape({}),
};

Expand All @@ -143,6 +156,8 @@ Password.defaultProps = {
disabled: false,
full: false,
style: undefined,
showPasswordAriaLabel: undefined,
hidePasswordAriaLabel: undefined,
};

export default Password;
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,7 @@ exports[`<Input /> Snapshots should match with helper text and max length 1`] =
Helper text
</span>
<span
aria-hidden="true"
class="c7"
>
0
Expand Down

0 comments on commit 01cd9be

Please sign in to comment.