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

fix: fixed the problem that after selecting a radio option, clicking outside does not trigger the onblur event #1977

Merged
merged 1 commit into from
Dec 15, 2023
Merged
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
14 changes: 14 additions & 0 deletions cypress/e2e/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ describe('Select', () => {
cy.get('.semi-select-option').eq(3).should('have.text', 'Xigua');
});

it('blur', () => {
cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--select-on-blur-on-focus', {
onBeforeLoad(win) {
cy.stub(win.console, 'log').as('consoleLog');
},
});

cy.get('.semi-select-selection').eq(0).click();
cy.get('.semi-select-option').eq(0).click();
cy.get('body').click('right');
cy.get('@consoleLog').should('be.calledWith', 'onBlur');

});

// it('ellipsisTrigger', () => {
// cy.visit('http://127.0.0.1:6006/iframe.html?path=/story/select--fix-1560');

Expand Down
2 changes: 1 addition & 1 deletion packages/semi-foundation/select/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export default class SelectFoundation extends BaseFoundation<SelectAdapter> {
this.close(e);
this._notifyBlur(e);
this._adapter.updateFocusState(false);
this._adapter.unregisterClickOutsideHandler();
Copy link
Collaborator

Choose a reason for hiding this comment

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

不能将 unregister 的操作跟空白点击绑定在一起。
假设用户是点击后打开 Select LOptionList,但是又通过 ref.close() 方式手动关闭了 select,此时是不存在触发 clickOutSide 逻辑的。 这个监听就会一直残留。但实际上 select 已经收起了,有残留监听是不合理的。

});
}

Expand All @@ -383,7 +384,6 @@ export default class SelectFoundation extends BaseFoundation<SelectAdapter> {
this._adapter.setIsFocusInContainer(false);
// this.unBindKeyBoardEvent();
// this._notifyBlur(e);
this._adapter.unregisterClickOutsideHandler();
// this._adapter.updateFocusState(false);

const isFilterable = this._isFilterable();
Expand Down
20 changes: 20 additions & 0 deletions packages/semi-ui/select/_story/select.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2207,11 +2207,13 @@ const BlurDemo = () => {
const onBlur = (value, e) => {
console.log(value);
console.log(e);
console.log('onBlur');
};

const onFocus = (value, e) => {
console.log(value);
console.log(e);
console.log('onFocus');
};

return (
Expand All @@ -2230,6 +2232,24 @@ const BlurDemo = () => {
<Select.Option value="deguo">Germany</Select.Option>
<Select.Option value="faguo">France</Select.Option>
</Select>
<br />
<br />
<br />
<Select
filter
placeholder="多选"
style={{
width: 180,
}}
onBlur={onBlur}
onFocus={onFocus}
multiple
>
<Select.Option value="zhongguo">China</Select.Option>
<Select.Option value="hanguo">Korea</Select.Option>
<Select.Option value="deguo">Germany</Select.Option>
<Select.Option value="faguo">France</Select.Option>
</Select>
</>
);
};
Expand Down
Loading