Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v10): backport a11y fixes for UIShell, FileUploaderButton #14517

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class FileUploader extends React.Component {
<span
key={index}
className={selectedFileClasses}
ref={(node) => (this.nodes[index] = node)} // eslint-disable-line
ref={(node) => (this.nodes[index] = node)}
{...other}>
<p className={`${prefix}--file-filename`}>{name}</p>
<span className={`${prefix}--file__state-container`}>
Expand Down
28 changes: 17 additions & 11 deletions packages/react/src/components/FileUploader/FileUploaderButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function FileUploaderButton({
labelText: ownerLabelText = 'Add file',
multiple = false,
onChange = noop,
role = 'button',
name,
size = 'md',
tabIndex = 0,
Expand All @@ -53,10 +52,16 @@ function FileUploaderButton({

function onClick(event) {
event.target.value = null;
if (inputNode.current) {
inputNode.current.value = '';
inputNode.current.click();
}
}

function onKeyDown(event) {
if (matches(event, [keys.Enter, keys.Space])) {
event.preventDefault();
if (matches(event, [keys.Enter, keys.Space]) && inputNode.current) {
inputNode.current.value = '';
inputNode.current.click();
}
}
Expand All @@ -76,29 +81,30 @@ function FileUploaderButton({

return (
<>
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}
<label
tabIndex={disabled ? -1 : tabIndex || 0}
<button
type="button"
disabled={disabled}
className={classes}
onClick={onClick}
onKeyDown={onKeyDown}
htmlFor={inputId}
tabIndex={tabIndex ? tabIndex : undefined}
{...other}>
<span role={role} aria-disabled={disabled}>
{labelText}
</span>
{labelText}
</button>
<label className={`${prefix}--visually-hidden`} htmlFor={inputId}>
<span>{labelText}</span>
</label>
<input
className={`${prefix}--visually-hidden`}
ref={inputNode}
id={inputId}
disabled={disabled}
type="file"
tabIndex="-1"
tabIndex={-1}
multiple={multiple}
accept={accept}
name={name}
onChange={handleOnChange}
onClick={onClick}
/>
</>
);
Expand Down
20 changes: 4 additions & 16 deletions packages/react/src/components/UIShell/HeaderPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,31 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import { AriaLabelPropType } from '../../prop-types/AriaPropTypes';
import { usePrefix } from '../../internal/usePrefix';

const HeaderPanel = React.forwardRef(function HeaderPanel(
{
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
children,
className: customClassName,
expanded,
...other
},
{ children, className: customClassName, expanded, ...other },
ref
) {
const prefix = usePrefix();
const accessibilityLabel = {
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
};

const className = cx(`${prefix}--header-panel`, {
[`${prefix}--header-panel--expanded`]: expanded,
[customClassName]: !!customClassName,
});

return (
<div {...other} className={className} {...accessibilityLabel} ref={ref}>
<div {...other} className={className} ref={ref}>
{children}
</div>
);
});

HeaderPanel.propTypes = {
/**
* Required props for accessibility label on the underlying menu
* The content that will render inside of the `HeaderPanel`
*/
...AriaLabelPropType,
children: PropTypes.node,
tw15egan marked this conversation as resolved.
Show resolved Hide resolved

/**
* Optionally provide a custom class to apply to the underlying `<li>` node
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/UIShell/UIShell-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ export const HeaderBaseWActionsAndRightPanel = withReadme(readme, () => {
<Notification20 />
</HeaderGlobalAction>
</HeaderGlobalBar>
<HeaderPanel aria-label="Header Panel" expanded={expanded} />
<HeaderPanel expanded={expanded} />
</Header>
);
});
Expand Down Expand Up @@ -590,7 +590,7 @@ export const HeaderBaseWActionsAndSwitcher = withReadme(readme, () => (
<AppSwitcher20 />
</HeaderGlobalAction>
</HeaderGlobalBar>
<HeaderPanel aria-label="Header Panel" expanded>
<HeaderPanel expanded>
<Switcher aria-label="Switcher Container">
<SwitcherItem isSelected aria-label="Link 1" href="#">
Link 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export const HeaderBaseWActionsAndRightPanel = () => (
<AppSwitcher20 />
</HeaderGlobalAction>
</HeaderGlobalBar>
<HeaderPanel aria-label="Header Panel" expanded />
<HeaderPanel expanded />
</Header>
);

Expand Down Expand Up @@ -576,7 +576,7 @@ export const HeaderBaseWActionsAndSwitcher = () => (
<AppSwitcher20 />
</HeaderGlobalAction>
</HeaderGlobalBar>
<HeaderPanel aria-label="Header Panel" expanded>
<HeaderPanel expanded>
<Switcher aria-label="Switcher Container">
<SwitcherItem isSelected aria-label="Link 1" href="#">
Link 1
Expand Down