Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 5a79db3

Browse files
Issue 660 - Increase page_current and page_count fields size to accommodate larger numbers (#819)
1 parent 586c567 commit 5a79db3

File tree

4 files changed

+111
-44
lines changed

4 files changed

+111
-44
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
### Fixed
77
- [#817](https://github.com/plotly/dash-table/pull/817) Fix a regression introduced with [#722](https://github.com/plotly/dash-table/pull/722) causing the tooltips to be misaligned with respect to their parent cell
88
- [#818](https://github.com/plotly/dash-table/pull/818) Fix a regression causing copy/paste not to work when selecting a range of cells with Shift + mouse click
9+
- [#819](https://github.com/plotly/dash-table/pull/819) Fix pagination `page_current` and `page_count` fields to accommodate larger numbers
910

1011
## [4.9.0] - 2020-07-27
1112
### Added

src/dash-table/components/PageNavigation/index.tsx

+33-18
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ export default class PageNavigation extends Component<IPageNavigationProps> {
2323
render() {
2424
const {paginator, page_current} = this.props;
2525

26-
return paginator.lastPage !== undefined &&
27-
paginator.lastPage <= 0 ? null : (
26+
if (paginator.lastPage !== undefined && paginator.lastPage <= 0) {
27+
return null;
28+
}
29+
30+
const pageChars = Math.max(
31+
3,
32+
((paginator.lastPage ?? 0) + 1).toString().length
33+
);
34+
const minWidth = `${pageChars + 1}ch`;
35+
36+
return (
2837
<div className='previous-next-container'>
2938
<button
3039
className='first-page'
@@ -43,26 +52,32 @@ export default class PageNavigation extends Component<IPageNavigationProps> {
4352
</button>
4453

4554
<div className='page-number'>
46-
<input
47-
type='text'
48-
className='current-page'
49-
onBlur={event => {
50-
this.goToPage(event.target.value);
51-
event.target.value = '';
52-
}}
53-
onKeyDown={event => {
54-
if (event.keyCode === KEY_CODES.ENTER) {
55-
event.currentTarget.blur();
56-
}
57-
}}
58-
placeholder={(page_current + 1).toString()}
59-
defaultValue=''
60-
></input>
55+
<div className='current-page-container'>
56+
<div className='current-page-shadow' style={{minWidth}}>
57+
{(page_current + 1).toString()}
58+
</div>
59+
<input
60+
type='text'
61+
className='current-page'
62+
style={{minWidth}}
63+
onBlur={event => {
64+
this.goToPage(event.target.value);
65+
event.target.value = '';
66+
}}
67+
onKeyDown={event => {
68+
if (event.keyCode === KEY_CODES.ENTER) {
69+
event.currentTarget.blur();
70+
}
71+
}}
72+
placeholder={(page_current + 1).toString()}
73+
defaultValue=''
74+
></input>
75+
</div>
6176

6277
{paginator.lastPage !== undefined ? ' / ' : ''}
6378

6479
{paginator.lastPage !== undefined ? (
65-
<div className='last-page'>
80+
<div className='last-page' style={{minWidth}}>
6681
{paginator.lastPage + 1}
6782
</div>
6883
) : (

src/dash-table/components/Table/Table.less

+35-23
Original file line numberDiff line numberDiff line change
@@ -143,41 +143,53 @@
143143

144144
.dash-table-container {
145145
.previous-next-container {
146-
display: inline-block;
147146
float: right;
148147
padding: 5px 0px;
149148

150149
.page-number {
151150
font-family: monospace;
152151
display: inline-block;
152+
153153
.last-page {
154-
min-width: 30px;
155-
display: inline-block;
156-
text-align: center;
157-
margin: 0.5em;
154+
display: inline-block;
155+
text-align: center;
156+
padding: 1px 2px;
158157
}
159-
}
160158

161-
input.current-page {
162-
display: inline-block;
163-
border-bottom: solid lightgrey 1px !important;
164-
color: black;
165-
border: none;
166-
width: 30px;
167-
text-align: center;
168-
font-family: monospace;
169-
font-size: 10pt;
170-
margin: 0.5em;
159+
.current-page-container {
160+
display: inline-block;
161+
position: relative;
171162

172-
&::placeholder {
173-
color: black;
174-
}
163+
.current-page-shadow,
164+
input.current-page {
165+
display: inline-block;
166+
border-bottom: solid lightgrey 1px !important;
167+
color: black;
168+
border: none;
169+
text-align: center;
170+
font-family: monospace;
171+
font-size: 10pt;
172+
padding: 1px 2px;
173+
174+
&::placeholder {
175+
color: black;
176+
}
175177

176-
&:focus {
177-
outline: none;
178+
&:focus {
179+
outline: none;
178180

179-
&::placeholder {
180-
opacity: 0;
181+
&::placeholder {
182+
opacity: 0;
183+
}
184+
}
185+
}
186+
187+
input.current-page {
188+
position: absolute;
189+
top: 0;
190+
left: 0;
191+
width: 100%;
192+
height: 100%;
181193
}
182194
}
183195
}

tests/visual/percy-storybook/Style.percy.tsx

+42-3
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,49 @@ storiesOf('DashTable/Style type condition', module)
384384
style_data_conditional={[{
385385
if: { column_editable: true }, background_color: 'MediumPurple'
386386
}]}
387-
pagination_settings={{
388-
current_page: 0,
389-
page_size: 10
387+
page_current={0}
388+
page_size={10}
389+
/>))
390+
.add('large current page', () => (<DataTable
391+
id='paging-large-current-page'
392+
data={mock.data.slice(0, 10)}
393+
columns={mock.columns.map((col: any) => R.merge(col, {
394+
name: col.name,
395+
deletable: true
396+
}))}
397+
style_table={{
398+
width: '100%'
390399
}}
400+
row_deletable={true}
401+
row_selectable={true}
402+
pagination_mode={'fe'}
403+
style_data_conditional={[{
404+
if: { column_editable: true }, background_color: 'MediumPurple'
405+
}]}
406+
page_action='custom'
407+
page_count={999999}
408+
page_current={987654}
409+
page_size={10}
410+
/>))
411+
.add('large current page and unknown page count', () => (<DataTable
412+
id='paging-large-current-page'
413+
data={mock.data.slice(0, 10)}
414+
columns={mock.columns.map((col: any) => R.merge(col, {
415+
name: col.name,
416+
deletable: true
417+
}))}
418+
style_table={{
419+
width: '100%'
420+
}}
421+
row_deletable={true}
422+
row_selectable={true}
423+
pagination_mode={'fe'}
424+
style_data_conditional={[{
425+
if: { column_editable: true }, background_color: 'MediumPurple'
426+
}]}
427+
page_action='custom'
428+
page_current={987654}
429+
page_size={10}
391430
/>))
392431
.add('data column_id array', () => (<DataTable
393432
{...DEFAULT_TABLE}

0 commit comments

Comments
 (0)