@douyinfe/semi-ui 2.38.0 → 2.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,7 @@ var _trigger = _interopRequireDefault(require("../trigger"));
20
20
  var _option = _interopRequireDefault(require("./option"));
21
21
  var _warning = _interopRequireDefault(require("@douyinfe/semi-foundation/lib/cjs/utils/warning"));
22
22
  require("@douyinfe/semi-foundation/lib/cjs/autoComplete/autoComplete.css");
23
+ var _reactDom = _interopRequireDefault(require("react-dom"));
23
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25
  /* eslint-disable @typescript-eslint/ban-types, max-len */
25
26
 
@@ -147,6 +148,24 @@ class AutoComplete extends _baseComponent.default {
147
148
  this.setState({
148
149
  rePosKey
149
150
  });
151
+ },
152
+ registerClickOutsideHandler: cb => {
153
+ const clickOutsideHandler = e => {
154
+ const optionInstance = this.optionsRef && this.optionsRef.current;
155
+ const triggerDom = this.triggerRef && this.triggerRef.current;
156
+ const optionsDom = _reactDom.default.findDOMNode(optionInstance);
157
+ const target = e.target;
158
+ if (optionsDom && (!optionsDom.contains(target) || !optionsDom.contains(target.parentNode)) && triggerDom && !triggerDom.contains(target)) {
159
+ cb(e);
160
+ }
161
+ };
162
+ this.clickOutsideHandler = clickOutsideHandler;
163
+ document.addEventListener('mousedown', clickOutsideHandler, false);
164
+ },
165
+ unregisterClickOutsideHandler: () => {
166
+ if (this.clickOutsideHandler) {
167
+ document.removeEventListener('mousedown', this.clickOutsideHandler, false);
168
+ }
150
169
  }
151
170
  });
152
171
  }
@@ -15,6 +15,7 @@ import Trigger from '../trigger';
15
15
  import Option from './option';
16
16
  import warning from '@douyinfe/semi-foundation/lib/es/utils/warning';
17
17
  import '@douyinfe/semi-foundation/lib/es/autoComplete/autoComplete.css';
18
+ import ReactDOM from 'react-dom';
18
19
  const prefixCls = cssClasses.PREFIX;
19
20
  const sizeSet = strings.SIZE;
20
21
  const positionSet = strings.POSITION;
@@ -139,6 +140,24 @@ class AutoComplete extends BaseComponent {
139
140
  this.setState({
140
141
  rePosKey
141
142
  });
143
+ },
144
+ registerClickOutsideHandler: cb => {
145
+ const clickOutsideHandler = e => {
146
+ const optionInstance = this.optionsRef && this.optionsRef.current;
147
+ const triggerDom = this.triggerRef && this.triggerRef.current;
148
+ const optionsDom = ReactDOM.findDOMNode(optionInstance);
149
+ const target = e.target;
150
+ if (optionsDom && (!optionsDom.contains(target) || !optionsDom.contains(target.parentNode)) && triggerDom && !triggerDom.contains(target)) {
151
+ cb(e);
152
+ }
153
+ };
154
+ this.clickOutsideHandler = clickOutsideHandler;
155
+ document.addEventListener('mousedown', clickOutsideHandler, false);
156
+ },
157
+ unregisterClickOutsideHandler: () => {
158
+ if (this.clickOutsideHandler) {
159
+ document.removeEventListener('mousedown', this.clickOutsideHandler, false);
160
+ }
142
161
  }
143
162
  });
144
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-ui",
3
- "version": "2.38.0",
3
+ "version": "2.38.1",
4
4
  "description": "",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es/index.js",
@@ -17,12 +17,12 @@
17
17
  "lib/*"
18
18
  ],
19
19
  "dependencies": {
20
- "@douyinfe/semi-animation": "2.38.0",
21
- "@douyinfe/semi-animation-react": "2.38.0",
22
- "@douyinfe/semi-foundation": "2.38.0",
23
- "@douyinfe/semi-icons": "2.38.0",
24
- "@douyinfe/semi-illustrations": "2.38.0",
25
- "@douyinfe/semi-theme-default": "2.38.0",
20
+ "@douyinfe/semi-animation": "2.38.1",
21
+ "@douyinfe/semi-animation-react": "2.38.1",
22
+ "@douyinfe/semi-foundation": "2.38.1",
23
+ "@douyinfe/semi-icons": "2.38.1",
24
+ "@douyinfe/semi-illustrations": "2.38.1",
25
+ "@douyinfe/semi-theme-default": "2.38.1",
26
26
  "async-validator": "^3.5.0",
27
27
  "classnames": "^2.2.6",
28
28
  "copy-text-to-clipboard": "^2.1.1",
@@ -69,7 +69,7 @@
69
69
  ],
70
70
  "author": "",
71
71
  "license": "MIT",
72
- "gitHead": "5071ee1b4e93db7ce101dec8ef20ed32031bd297",
72
+ "gitHead": "aaad3c86114e9bd2d9a61c8b78260e18ffc0eec6",
73
73
  "devDependencies": {
74
74
  "@babel/plugin-proposal-decorators": "^7.15.8",
75
75
  "@babel/plugin-transform-runtime": "^7.15.8",