@skbkontur/react-ui 4.15.3 → 4.15.5

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.15.5](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@4.15.4...@skbkontur/react-ui@4.15.5) (2023-08-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **InputLikeText:** use debounce to control async content selection ([#3226](https://github.com/skbkontur/retail-ui/issues/3226)) ([18e5947](https://github.com/skbkontur/retail-ui/commit/18e5947086f0a6b161b4fc0d40412a600131337f))
12
+
13
+
14
+
15
+
16
+
17
+ ## [4.15.4](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@4.15.3...@skbkontur/react-ui@4.15.4) (2023-07-24)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * a correct republish of the previous release
23
+
24
+
25
+
26
+
27
+
6
28
  ## [4.15.3](https://github.com/skbkontur/retail-ui/compare/@skbkontur/react-ui@4.15.2...@skbkontur/react-ui@4.15.3) (2023-07-21)
7
29
 
8
30
 
@@ -9,6 +9,7 @@ import { Select } from '../../Select';
9
9
  import { DateInput, DateInputProps } from '../DateInput';
10
10
  import { LangCodes, LocaleContext } from '../../../lib/locale';
11
11
  import { defaultLangCode } from '../../../lib/locale/constants';
12
+ import { InternalDateGetter } from '../../../lib/date/InternalDateGetter';
12
13
 
13
14
  interface DateInputFormattingState {
14
15
  order: InternalDateOrder;
@@ -239,11 +240,21 @@ class DateInputSimple extends React.Component<DateInputSimpleProps> {
239
240
  }
240
241
 
241
242
  class DateInputLastEvent extends React.Component {
243
+ private getTodayComponents = InternalDateGetter.getTodayComponents;
242
244
  public state = {
243
245
  lastEvent: 'none',
244
246
  };
245
247
 
248
+ public handleFocus = () => {
249
+ InternalDateGetter.getTodayComponents = () => ({
250
+ date: 1,
251
+ month: 1,
252
+ year: 2000,
253
+ });
254
+ };
255
+
246
256
  public handleBlur = () => {
257
+ InternalDateGetter.getTodayComponents = this.getTodayComponents;
247
258
  this.setState({ lastEvent: 'blur' });
248
259
  };
249
260
 
@@ -254,7 +265,12 @@ class DateInputLastEvent extends React.Component {
254
265
  public render() {
255
266
  return (
256
267
  <Gapped>
257
- <DateInputSimple onValueChange={this.handleChange} onBlur={this.handleBlur} defaultValue="21.12.2012" />
268
+ <DateInputSimple
269
+ onValueChange={this.handleChange}
270
+ onBlur={this.handleBlur}
271
+ onFocus={this.handleFocus}
272
+ defaultValue="21.12.2012"
273
+ />
258
274
  <div>{this.state.lastEvent}</div>
259
275
  </Gapped>
260
276
  );
@@ -379,15 +395,6 @@ BlurAlwaysAfterChange.parameters = {
379
395
  await this.expect(await this.takeScreenshot()).to.matchImage('value changed');
380
396
  },
381
397
  async 'value restored'() {
382
- await this.browser.executeScript(function () {
383
- // @ts-expect-error: `window` object doesn't expose types by default. See: https://github.com/microsoft/TypeScript/issues/19816.
384
- window.OldDate = window.Date;
385
- // @ts-expect-error: Read the comment above.
386
- window.Date = function () {
387
- // @ts-expect-error: Read the comment above.
388
- return new window.OldDate(2000, 0, 1);
389
- };
390
- });
391
398
  await this.browser.executeScript(function () {
392
399
  const input = window.document.querySelector("[data-comp-name~='DateInput']");
393
400
  if (input instanceof HTMLElement) {
@@ -402,10 +409,9 @@ BlurAlwaysAfterChange.parameters = {
402
409
  .click(this.browser.findElement({ css: 'body' }))
403
410
  .perform();
404
411
  await this.browser.executeScript(function () {
405
- // @ts-expect-error: `window` object doesn't expose types by default. See: https://github.com/microsoft/TypeScript/issues/19816.
406
- if (window.OldDate) {
407
- // @ts-expect-error: Read the comment above.
408
- window.Date = window.OldDate;
412
+ const input = window.document.querySelector("[data-comp-name~='DateInput']");
413
+ if (input instanceof HTMLElement) {
414
+ input.blur();
409
415
  }
410
416
  });
411
417
  await this.expect(await this.takeScreenshot()).to.matchImage('value restored');
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
3
  import React from 'react';
4
4
  import ReactDOM from 'react-dom';
5
+ import debounce from 'lodash.debounce';
5
6
 
6
7
  import { isNonNullable } from '../../lib/utils';
7
8
  import { isKeyTab, isShortcutPaste } from '../../lib/events/keyboard/identifiers';
@@ -100,6 +101,9 @@ export class InputLikeText extends React.Component<InputLikeTextProps, InputLike
100
101
  return this.node;
101
102
  }
102
103
 
104
+ // Async call required for Firefox
105
+ private selectNodeContentsDebounced = debounce(selectNodeContents, 0);
106
+
103
107
  public selectInnerNode = (node: HTMLElement | null, start = 0, end = 1) => {
104
108
  if (this.dragging || !node) {
105
109
  return;
@@ -112,7 +116,8 @@ export class InputLikeText extends React.Component<InputLikeTextProps, InputLike
112
116
  this.frozenBlur = true;
113
117
 
114
118
  this.lastSelectedInnerNode = [node, start, end];
115
- setTimeout(() => selectNodeContents(node, start, end), 0);
119
+ this.selectNodeContentsDebounced(node, start, end);
120
+
116
121
  if (this.focusTimeout) {
117
122
  clearInterval(this.focusTimeout);
118
123
  }
@@ -465,6 +470,7 @@ export class InputLikeText extends React.Component<InputLikeTextProps, InputLike
465
470
  };
466
471
 
467
472
  private handleBlur = (e: React.FocusEvent<HTMLElement>) => {
473
+ this.selectNodeContentsDebounced.cancel();
468
474
  if (isMobile) {
469
475
  e.target.removeAttribute('contenteditable');
470
476
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@skbkontur/react-ui",
3
- "version": "4.15.3",
3
+ "version": "4.15.5",
4
4
  "description": "UI Components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "index.js",
7
7
  "sideEffects": false,
8
- "homepage": "https://tech.skbkontur.ru/react-ui/4.15.3/",
8
+ "homepage": "https://tech.skbkontur.ru/react-ui/4.15.5/",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git@github.com:skbkontur/retail-ui.git"