Repository navigation
Editors: get rid of the ctor overrides #34925
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
Merged
EugeniyKiyashko
merged 6 commits into
DevExpress:main
from
EugeniyKiyashko:typescript/ui/editor_drop_ctor_26_2
Aug 26, 2026
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca598e3
Editor: replace the ctor override with _createElement
EugeniyKiyashko a3e49a6
TextEditor: get rid of the ctor override
EugeniyKiyashko 6de0784
TextBox: get rid of the ctor override
EugeniyKiyashko 0c77488
Overlay, Map: get rid of the ctor overrides
EugeniyKiyashko b07e269
Editor: move the validation state setup from _createElement to _init
EugeniyKiyashko 893523a
Editor: keep the validation state setup in _createElement
EugeniyKiyashko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/devextreme/js/__internal/ui/editor/__tests__/editor.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { | ||
| afterEach, describe, expect, it, | ||
| } from '@jest/globals'; | ||
| import { data } from '@js/core/element_data'; | ||
| import $ from '@js/core/renderer'; | ||
|
|
||
| import type { EditorProperties } from '../editor'; | ||
| import Editor from '../editor'; | ||
|
|
||
| const VALIDATION_TARGET = 'dx-validation-target'; | ||
|
|
||
| interface ValidationRequestArgs { | ||
| value: unknown; | ||
| editor: unknown; | ||
| } | ||
|
|
||
| class ProbeEditor extends Editor { | ||
| public hasValidationRequestOnOptionsInit?: boolean; | ||
|
|
||
| _initOptions(options: EditorProperties): void { | ||
| this.hasValidationRequestOnOptionsInit = Boolean(this.validationRequest); | ||
|
|
||
| super._initOptions(options); | ||
| } | ||
| } | ||
|
|
||
| const editors: ProbeEditor[] = []; | ||
|
|
||
| const createEditor = (options: Partial<EditorProperties> = {}): ProbeEditor => { | ||
| const element = $('<div>').appendTo(document.body).get(0) as HTMLElement; | ||
| // @ts-expect-error DOMComponent constructor is not typed for direct instantiation | ||
| const instance: ProbeEditor = new ProbeEditor(element, options); | ||
|
|
||
| editors.push(instance); | ||
|
|
||
| return instance; | ||
| }; | ||
|
|
||
| describe('Editor initialization', () => { | ||
| afterEach(() => { | ||
| editors.forEach((instance) => instance.dispose()); | ||
| editors.length = 0; | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('creates validationRequest before the options are initialized', () => { | ||
| const instance = createEditor(); | ||
|
|
||
| expect(instance.hasValidationRequestOnOptionsInit).toBe(true); | ||
| }); | ||
|
|
||
| it('marks the element as a validation target with the validation state ready', () => { | ||
| const instance = createEditor(); | ||
| const element = instance.$element().get(0) as HTMLElement; | ||
|
|
||
| expect(data(element, VALIDATION_TARGET)).toBe(instance); | ||
| expect(instance.validationRequest).toBeDefined(); | ||
| expect(instance.showValidationMessageTimeout).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('fires validationRequest when the value changes', () => { | ||
| const instance = createEditor({ value: 'initial' }); | ||
| const calls: ValidationRequestArgs[] = []; | ||
|
|
||
| instance.validationRequest.add((args: ValidationRequestArgs) => { | ||
| calls.push(args); | ||
| }); | ||
| instance.option('value', 'changed'); | ||
|
|
||
| expect(calls).toHaveLength(1); | ||
| expect(calls[0].value).toBe('changed'); | ||
| expect(calls[0].editor).toBe(instance); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/devextreme/js/__internal/ui/text_box/__tests__/text_box.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { | ||
| afterEach, describe, expect, it, | ||
| } from '@jest/globals'; | ||
| import $ from '@js/core/renderer'; | ||
|
|
||
| import TextBox, { type TextBoxProperties } from '../text_box'; | ||
|
|
||
| const textBoxes: TextBox[] = []; | ||
|
|
||
| const createTextBox = (options: Partial<TextBoxProperties> = {}): TextBox => { | ||
| const element = $('<div>').appendTo(document.body).get(0) as HTMLElement; | ||
| // @ts-expect-error DOMComponent constructor is not typed for direct instantiation | ||
| const instance: TextBox = new TextBox(element, options); | ||
|
|
||
| textBoxes.push(instance); | ||
|
|
||
| return instance; | ||
| }; | ||
|
|
||
| describe('TextBox search mode and the clear button', () => { | ||
| afterEach(() => { | ||
| textBoxes.forEach((instance) => instance.dispose()); | ||
| textBoxes.length = 0; | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('turns the clear button on in search mode when showClearButton is not specified', () => { | ||
| const instance = createTextBox({ mode: 'search' }); | ||
|
|
||
| expect(instance.option('showClearButton')).toBe(true); | ||
| }); | ||
|
|
||
| it('keeps showClearButton disabled in search mode when it is specified explicitly (T218573)', () => { | ||
| const instance = createTextBox({ mode: 'search', showClearButton: false }); | ||
|
|
||
| expect(instance.option('showClearButton')).toBe(false); | ||
| }); | ||
|
|
||
| it('restores the original showClearButton when search mode is turned off', () => { | ||
| const instance = createTextBox({ mode: 'search' }); | ||
|
|
||
| expect(instance.option('showClearButton')).toBe(true); | ||
|
|
||
| instance.option('mode', 'text'); | ||
|
|
||
| expect(instance.option('showClearButton')).toBe(false); | ||
| }); | ||
| }); |
68 changes: 68 additions & 0 deletions
68
packages/devextreme/js/__internal/ui/text_box/__tests__/text_editor.base.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { | ||
| afterEach, describe, expect, it, | ||
| } from '@jest/globals'; | ||
| import $ from '@js/core/renderer'; | ||
|
|
||
| import TextEditor from '../text_editor'; | ||
| import type { TextEditorBaseProperties } from '../text_editor.base'; | ||
|
|
||
| class ProbeTextEditor extends TextEditor { | ||
| public hasButtonCollectionOnInitMarkup?: boolean; | ||
|
|
||
| _initMarkup(): void { | ||
| this.hasButtonCollectionOnInitMarkup = Boolean(this._buttonCollection); | ||
|
|
||
| super._initMarkup(); | ||
| } | ||
| } | ||
|
|
||
| const editors: ProbeTextEditor[] = []; | ||
|
|
||
| const createEditor = (options: Partial<TextEditorBaseProperties> = {}): ProbeTextEditor => { | ||
| const element = $('<div>').appendTo(document.body).get(0) as HTMLElement; | ||
| // @ts-expect-error DOMComponent constructor is not typed for direct instantiation | ||
| const instance: ProbeTextEditor = new ProbeTextEditor(element, options); | ||
|
|
||
| editors.push(instance); | ||
|
|
||
| return instance; | ||
| }; | ||
|
|
||
| const customButton: NonNullable<TextEditorBaseProperties['buttons']> = [ | ||
| { name: 'custom', location: 'after', options: { text: 'Go' } }, | ||
| ]; | ||
|
|
||
| describe('TextEditorBase buttons initialization', () => { | ||
| afterEach(() => { | ||
| editors.forEach((instance) => instance.dispose()); | ||
| editors.length = 0; | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('creates the button collection before the markup is rendered', () => { | ||
| const instance = createEditor(); | ||
|
|
||
| expect(instance.hasButtonCollectionOnInitMarkup).toBe(true); | ||
| }); | ||
|
|
||
| it('renders a button declared in the buttons option', () => { | ||
| const instance = createEditor({ buttons: customButton }); | ||
|
|
||
| expect(instance.getButton('custom')).toBeDefined(); | ||
| expect(instance._$afterButtonsContainer).not.toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the declared button again after repaint', () => { | ||
| const instance = createEditor({ buttons: customButton }); | ||
|
|
||
| instance.repaint(); | ||
|
|
||
| expect(instance.getButton('custom')).toBeDefined(); | ||
| }); | ||
|
|
||
| it('throws E1053 when the buttons option is not an array', () => { | ||
| expect(() => createEditor({ | ||
| buttons: 'custom' as unknown as TextEditorBaseProperties['buttons'], | ||
| })).toThrow(/E1053/); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.