Skip to content

Commit

Permalink
fix(Select): should prevent scroll when click wrapper, close #4492 (#…
Browse files Browse the repository at this point in the history
…4504)

* fix(Select): should prevent scroll when click wrapper

---------

Co-authored-by: chenkeyao.chenkeya <[email protected]>
  • Loading branch information
kyokaxin and chenkeyao.chenkeya authored Oct 31, 2023
1 parent bf5bf12 commit dae8daf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/input/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ class Base extends React.Component {
return this.inputRef;
}

focus(start, end) {
this.inputRef.focus();
focus(start, end, preventScroll = false) {
this.inputRef.focus({ preventScroll });
if (typeof start === 'number') {
this.inputRef.selectionStart = start;
}
Expand Down
2 changes: 1 addition & 1 deletion src/select/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export default class Base extends React.Component {
* @override
*/
focusInput() {
this.inputRef.focus();
this.inputRef.focus(undefined, undefined, true);
}

focus(...args) {
Expand Down
17 changes: 17 additions & 0 deletions test/select/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,23 @@ describe('AutoComplete', () => {
}, 200);
});

it('should prevent scroll when click wrapper', async () => {
wrapper = mount(
<div className="select-scroll-wrapper" style={{ width: 300, overflowX: 'scroll' }}>
<Select
style={{ width: 540 }}
dataSource={[
{ label: 'xxx', value: 'yyy' },
{ label: 'empty', value: '' },
]}/>
</div>
);
const selectWrapper = wrapper.find('.select-scroll-wrapper').getDOMNode();
const prevScrollLeft = selectWrapper.scrollLeft;
ReactTestUtils.Simulate.click(selectWrapper);
assert(wrapper.find('.select-scroll-wrapper').getDOMNode().scrollLeft === prevScrollLeft);
})

describe('react api', () => {
it('calls componentWillReceiveProps', done => {
wrapper.setProps({ value: '30' });
Expand Down

0 comments on commit dae8daf

Please sign in to comment.