Skip to content

Commit

Permalink
rename ariaLabel to defaultAriaLabel & fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrookes committed Feb 4, 2020
1 parent 8d69349 commit 3d83a66
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 58 deletions.
2 changes: 1 addition & 1 deletion packages/material-ui-lab/src/Pagination/usePagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function usePagination(props = {}) {
}, 240);
};

https://dev.to/namirsab/comment/2050
// https://dev.to/namirsab/comment/2050
const range = (start, end) => {
const length = end - start + 1;
return Array.from({ length }, (_, i) => start + i);
Expand Down
112 changes: 55 additions & 57 deletions packages/material-ui-lab/src/PaginationItem/PaginationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const styles = theme => ({
outlined: {
border: `1px solid ${
theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'
}`,
}`,
'&:hover, &:focus': {
backgroundColor: theme.palette.action.hover,
},
Expand All @@ -68,7 +68,7 @@ export const styles = theme => ({
backgroundColor: 'rgba(0, 0, 0, 0.03)',
border: `1px solid ${
theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.13)' : 'rgba(255, 255, 255, 0.13)'
}`,
}`,
pointerEvents: 'none',
},
'&$selected': {
Expand Down Expand Up @@ -226,7 +226,7 @@ export const styles = theme => ({
selected: {},
});

function ariaLabel(type, page, selected) {
function defaultGetAriaLabel(type, page, selected) {
if (type === 'page') {
return `${selected ? '' : 'go to '}page ${page}`;
}
Expand All @@ -240,7 +240,7 @@ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
color = 'standard',
component,
disabled = false,
getAriaLabel,
getAriaLabel = defaultGetAriaLabel,
page,
onClick: handleClick,
selected,
Expand All @@ -262,60 +262,58 @@ const PaginationItem = React.forwardRef(function PaginationItem(props, ref) {
</div>
) : (
<ButtonBase
ref={ref}
component={component}
disabled={disabled}
aria-label={
getAriaLabel ? getAriaLabel(type, page, selected) : ariaLabel(type, page, selected)
}
aria-current={selected ? 'page' : undefined}
onClick={event => handleClick(event, page)}
className={clsx(
classes.root,
classes[variant],
classes[shape],
{
[classes[`${variant}${capitalize(color)}`]]: color !== 'standard',
[classes.disabled]: disabled,
[classes.selected]: selected,
[classes[`size${capitalize(size)}`]]: size !== 'medium',
},
className,
)}
{...other}
>
{type === 'page' && page}
{type === 'previous' && (
<NavigateBeforeIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
{type === 'next' && (
<NavigateNextIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
{type === 'first' && (
<FirstPageIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
{type === 'last' && (
<LastPageIcon
className={clsx(classes.icon, {
<ButtonBase
ref={ref}
component={component}
disabled={disabled}
aria-label={getAriaLabel(type, page, selected)}
aria-current={selected ? 'page' : undefined}
onClick={event => handleClick(event, page)}
className={clsx(
classes.root,
classes[variant],
classes[shape],
{
[classes[`${variant}${capitalize(color)}`]]: color !== 'standard',
[classes.disabled]: disabled,
[classes.selected]: selected,
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
</ButtonBase>
);
},
className,
)}
{...other}
>
{type === 'page' && page}
{type === 'previous' && (
<NavigateBeforeIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
{type === 'next' && (
<NavigateNextIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
{type === 'first' && (
<FirstPageIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
{type === 'last' && (
<LastPageIcon
className={clsx(classes.icon, {
[classes[`size${capitalize(size)}`]]: size !== 'medium',
})}
/>
)}
</ButtonBase>
);
});

PaginationItem.propTypes = {
Expand Down

0 comments on commit 3d83a66

Please sign in to comment.