diff --git a/packages/react-core/src/components/Pagination/OptionsToggle.tsx b/packages/react-core/src/components/Pagination/OptionsToggle.tsx index bb797b828ad..43c02e56f1a 100644 --- a/packages/react-core/src/components/Pagination/OptionsToggle.tsx +++ b/packages/react-core/src/components/Pagination/OptionsToggle.tsx @@ -9,9 +9,9 @@ import { DropdownToggle } from '../Dropdown'; export interface OptionsToggleProps extends React.HTMLProps { /** The type or title of the items being paginated */ itemsTitle?: string; - /** Accessible label for the Options Toggle */ + /** Accessible label for the options toggle */ optionsToggle?: string; - /** The Title of the Pagination Options Menu */ + /** The title of the pagination options menu */ itemsPerPageTitle?: string; /** The first index of the items being paginated */ firstIndex?: number; @@ -19,15 +19,15 @@ export interface OptionsToggleProps extends React.HTMLProps { lastIndex?: number; /** The total number of items being paginated */ itemCount?: number; - /** Id added to the title of the Pagination Options Menu */ + /** Id added to the title of the pagination options menu */ widgetId?: string; /** showToggle */ showToggle?: boolean; - /** Event function that fires when user clicks the Options Menu toggle */ + /** Event function that fires when user clicks the options menu toggle */ onToggle?: (isOpen: boolean) => void; - /** Flag indicating if the Options Menu dropdown is open or not */ + /** Flag indicating if the options menu dropdown is open or not */ isOpen?: boolean; - /** Flag indicating if the Options Menu is disabled */ + /** Flag indicating if the options menu is disabled */ isDisabled?: boolean; /** */ parentRef?: HTMLElement; @@ -37,12 +37,16 @@ export interface OptionsToggleProps extends React.HTMLProps { onEnter?: () => void; /** Label for the English word "of" */ ofWord?: string; + /** Component to be used for wrapping the toggle contents. Use 'button' when you want + * all of the toggle text to be clickable. + */ + perPageComponent?: 'div' | 'button'; } let toggleId = 0; export const OptionsToggle: React.FunctionComponent = ({ itemsTitle = 'items', - optionsToggle = 'Items per page', + optionsToggle, // eslint-disable-next-line @typescript-eslint/no-unused-vars itemsPerPageTitle = 'Items per page', ofWord = 'of', @@ -57,43 +61,49 @@ export const OptionsToggle: React.FunctionComponent = ({ isDisabled = false, parentRef = null, toggleTemplate: ToggleTemplate, - onEnter = null -}: OptionsToggleProps) => ( -
- {showToggle && ( - - - {typeof ToggleTemplate === 'string' ? ( - fillTemplate(ToggleTemplate, { firstIndex, lastIndex, ofWord, itemCount, itemsTitle }) - ) : ( - - )} - - - - )} -
-); + onEnter = null, + perPageComponent = 'div' +}: OptionsToggleProps) => { + const isDiv = perPageComponent === 'div'; + const toggleClasses = css( + styles.optionsMenuToggle, + isDisabled && styles.modifiers.disabled, + styles.modifiers.plain, + styles.modifiers.text + ); + + const template = + typeof ToggleTemplate === 'string' ? ( + fillTemplate(ToggleTemplate, { firstIndex, lastIndex, ofWord, itemCount, itemsTitle }) + ) : ( + + ); + + const dropdown = showToggle && ( + + {isDiv && {template}} + + {!isDiv && template} + + + ); + + return isDiv ?
{dropdown}
: dropdown; +}; OptionsToggle.displayName = 'OptionsToggle'; diff --git a/packages/react-core/src/components/Pagination/Pagination.tsx b/packages/react-core/src/components/Pagination/Pagination.tsx index 926c2204446..ef7ff8e3c18 100644 --- a/packages/react-core/src/components/Pagination/Pagination.tsx +++ b/packages/react-core/src/components/Pagination/Pagination.tsx @@ -48,9 +48,9 @@ export interface PaginationTitles { pages?: string; /** The type or title of the items being paginated */ items?: string; - /** The Title of the Pagination Options Menu */ + /** The title of the pagination options menu */ itemsPerPage?: string; - /** The suffix to be displayed after each option on the Options Menu dropdown */ + /** The suffix to be displayed after each option on the options menu dropdown */ perPageSuffix?: string; /** Accessible label for the button which moves to the first page */ toFirstPage?: string; @@ -60,7 +60,7 @@ export interface PaginationTitles { toLastPage?: string; /** Accessible label for the button which moves to the next page */ toNextPage?: string; - /** Accessible label for the Options Toggle */ + /** Accessible label for the options toggle */ optionsToggle?: string; /** Accessible label for the input displaying the current page */ currPage?: string; @@ -141,6 +141,10 @@ export interface PaginationProps extends React.HTMLProps, OUIAPr onPageInput?: (event: React.SyntheticEvent, page: number) => void; /** Function called when user selects number of items per page. */ onPerPageSelect?: OnPerPageSelect; + /** Component to be used for wrapping the toggle contents. Use 'button' when you want + * all of the toggle text to be clickable. + */ + perPageComponent?: 'div' | 'button'; } const handleInputWidth = (lastPage: number, node: HTMLDivElement) => { @@ -177,7 +181,7 @@ export class Pagination extends React.Component undefined, onPageInput: () => undefined, onLastClick: () => undefined, - ouiaSafe: true + ouiaSafe: true, + perPageComponent: 'div' }; state = { @@ -252,6 +257,7 @@ export class Pagination extends React.Component { - /** Custom class name added to the Pagination Options Menu */ + /** Custom class name added to the pagination options menu */ className?: string; - /** Id added to the title of the Pagination Options Menu */ + /** Id added to the title of the Pagination options menu */ widgetId?: string; - /** Flag indicating if Pagination Options Menu is disabled */ + /** Flag indicating if pagination options menu is disabled */ isDisabled?: boolean; - /** Menu will open up or open down from the Options menu toggle */ + /** Menu will open up or open down from the options menu toggle */ dropDirection?: 'up' | 'down'; - /** Array of titles and values which will be the options on the Options Menu dropdown */ + /** Array of titles and values which will be the options on the options menu dropdown */ perPageOptions?: PerPageOptions[]; - /** The Title of the Pagination Options Menu */ + /** The title of the pagination options menu */ itemsPerPageTitle?: string; /** Current page number */ page?: number; - /** The suffix to be displayed after each option on the Options Menu dropdown */ + /** The suffix to be displayed after each option on the options menu dropdown */ perPageSuffix?: string; /** The type or title of the items being paginated */ itemsTitle?: string; - /** The text to be displayed on the Options Toggle */ + /** Accessible label for the options toggle */ optionsToggle?: string; /** The total number of items being paginated */ itemCount?: number; @@ -46,6 +46,10 @@ export interface PaginationOptionsMenuProps extends React.HTMLProps null as any + onPerPageSelect: () => null as any, + perPageComponent: 'div' }; constructor(props: PaginationOptionsMenuProps) { @@ -144,7 +149,8 @@ export class PaginationOptionsMenu extends React.Component } dropdownItems={this.renderItems()} diff --git a/packages/react-core/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap b/packages/react-core/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap index 294ac5dbf4c..0251e56a3fc 100644 --- a/packages/react-core/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap +++ b/packages/react-core/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap @@ -10,6 +10,7 @@ exports[`OptionsToggle should match snapshot (auto-generated) 1`] = ` /> + + + + +`; + exports[`Pagination component render should render correctly compact 1`] = `