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 all 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
3 changes: 3 additions & 0 deletions src/components/Paginator/Paginator.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ describe('Paginator', () => {
selectedPageIndex={1}
totalPages={3}
onPageSelect={onPageSelect}
TextField={{
isDisabled: true,
}}
/>
);
wrapper.find(TextField).prop(propName)(1, 3);
Expand Down
10 changes: 7 additions & 3 deletions src/components/Paginator/Paginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -108,7 +112,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 @@ -303,10 +307,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
90 changes: 90 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,90 @@
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>
);
},
});