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

BWAP-806 updating paginator component to hand textField properties #1242

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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
14 changes: 10 additions & 4 deletions src/components/Paginator/Paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
SingleSelectDumb as SingleSelect,
ISingleSelectState,
} from '../SingleSelect/SingleSelect';
import TextField, { ITextFieldProps } from '../TextField/TextField';
import TextField, {
ITextFieldProps,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: are both ITextFieldProps/ITextFieldPropsWithPassThroughs still used? else can be removed from the imports

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed with ITextFieldPropsWithPassThroughs

} from '../TextField/TextField';
import { IButtonProps, Button } from '../Button/Button';
import ArrowIcon from '../Icon/ArrowIcon/ArrowIcon';
import { buildModernHybridComponent } from '../../util/state-management';
Expand All @@ -35,6 +37,10 @@ type IPaginatorSingleSelectProps = Partial<ISingleSelectProps>;

type ShowTotalObjects = (count: number) => string;

interface IExtendedTextFieldProps extends Omit<ITextFieldProps, 'value'> {
Copy link
Member

@tsantef tsantef Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to redefine the value field?

value?: string;
}

export interface IPaginatorProps
extends StandardProps,
React.DetailedHTMLProps<
Expand Down Expand Up @@ -116,7 +122,7 @@ export interface IPaginatorProps
/** Object of TextField props which are passed thru to the underlying TextField component. */

//TextField: TextField.defaultProps;
TextField: ITextFieldProps;
TextField: IExtendedTextFieldProps;
}

export interface IPaginatorState {
Expand Down Expand Up @@ -311,10 +317,10 @@ class Paginator extends React.Component<IPaginatorProps, IPaginatorState> {
</Button>
<TextField
lazyLevel={100}
{...textFieldProps}
onBlur={this.handleTextFieldChange}
onSubmit={this.handleTextFieldChange}
isDisabled={isDisabled}
{...textFieldProps}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change of order would result in textFieldProps.isDisabled taking precedence over isDisabled.
if not intentional change, would leave the spread operator on the line above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout. Updated and added a test case as an example for this.

isDisabled={isDisabled || textFieldProps.isDisabled}
value={selectedPageIndex + 1}
/>
{!_.isNil(totalPages) && <span>of {totalPages.toLocaleString()}</span>}
Expand Down
87 changes: 87 additions & 0 deletions src/components/Paginator/examples/5.text-field-props.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import createClass from 'create-react-class';
import { Paginator } from '../../../index';

export default createClass({
getInitialState() {
return {
selectedPageIndex: 0,
};
},
render() {
return (
<div>
<p>A paginator where textField is disabled using textFieldProps.</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
isDisabled: true,
}}
/>
</section>

<p>A paginator where textField is not disabled using TextField props, but disabled from Paginator props</p>

<section>
<Paginator
isDisabled={true}
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
isDisabled: false,
}}
/>
</section>

<p>On submit</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
onSubmit: (value) => {
this.setState({ selectedPageIndex: value });
},
isDisabled: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless covered by another storybook example - also include an example if isDisabled: false (assume it is covered as the default value)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered by new storybook example

}}
/>
</section>

<p>On blur</p>

<section>
<Paginator
hasPageSizeSelector
showTotalObjects
totalCount={12321313}
SingleSelect={{
DropMenu: { direction: 'up' },
}}
TextField={{
value: this.state.selectedPageIndex,
onBlur: (value) => {
this.setState({ selectedPageIndex: value });
},
}}
/>
</section>
</div>
);
},
});