Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 3416fb2

Browse files
authored
Merge pull request #345 from ckeditor/i/6110
Other: Replaced `LabeledInputView` with `LabeledFieldView`. See ckeditor/ckeditor5#6110.
2 parents b3e2658 + f0ccd3f commit 3416fb2

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/imagetextalternative/imagetextalternativeui.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class ImageTextAlternativeUI extends Plugin {
117117

118118
this.listenTo( this._form, 'submit', () => {
119119
editor.execute( 'imageTextAlternative', {
120-
newValue: this._form.labeledInput.inputView.element.value
120+
newValue: this._form.labeledInput.fieldView.element.value
121121
} );
122122

123123
this._hideForm( true );
@@ -177,9 +177,9 @@ export default class ImageTextAlternativeUI extends Plugin {
177177
// stays unaltered) and re-opened it without changing the value of the command, they would see the
178178
// old value instead of the actual value of the command.
179179
// https://github.com/ckeditor/ckeditor5-image/issues/114
180-
labeledInput.value = labeledInput.inputView.element.value = command.value || '';
180+
labeledInput.fieldView.value = labeledInput.fieldView.element.value = command.value || '';
181181

182-
this._form.labeledInput.select();
182+
this._form.labeledInput.fieldView.select();
183183
}
184184

185185
/**

src/imagetextalternative/ui/textalternativeformview.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import View from '@ckeditor/ckeditor5-ui/src/view';
1111
import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
1212

1313
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
14-
import LabeledInputView from '@ckeditor/ckeditor5-ui/src/labeledinput/labeledinputview';
15-
import InputTextView from '@ckeditor/ckeditor5-ui/src/inputtext/inputtextview';
14+
15+
import LabeledFieldView from '@ckeditor/ckeditor5-ui/src/labeledfield/labeledfieldview';
16+
import { createLabeledInputText } from '@ckeditor/ckeditor5-ui/src/labeledfield/utils';
1617

1718
import submitHandler from '@ckeditor/ckeditor5-ui/src/bindings/submithandler';
1819
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
@@ -54,9 +55,9 @@ export default class TextAlternativeFormView extends View {
5455
this.keystrokes = new KeystrokeHandler();
5556

5657
/**
57-
* A textarea with a label.
58+
* An input with a label.
5859
*
59-
* @member {module:ui/labeledinput/labeledinputview~LabeledInputView} #labeledTextarea
60+
* @member {module:ui/labeledfield/labeledfieldview~LabeledFieldView} #labeledInput
6061
*/
6162
this.labeledInput = this._createLabeledInputView();
6263

@@ -181,14 +182,14 @@ export default class TextAlternativeFormView extends View {
181182
* Creates an input with a label.
182183
*
183184
* @private
184-
* @returns {module:ui/labeledinput/labeledinputview~LabeledInputView}
185+
* @returns {module:ui/labeledfield/labeledfieldview~LabeledFieldView} Labeled field view instance.
185186
*/
186187
_createLabeledInputView() {
187188
const t = this.locale.t;
188-
const labeledInput = new LabeledInputView( this.locale, InputTextView );
189+
const labeledInput = new LabeledFieldView( this.locale, createLabeledInputText );
189190

190191
labeledInput.label = t( 'Text alternative' );
191-
labeledInput.inputView.placeholder = t( 'Text alternative' );
192+
labeledInput.fieldView.placeholder = t( 'Text alternative' );
192193

193194
return labeledInput;
194195
}

tests/imagetextalternative/imagetextalternativeui.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,42 @@ describe( 'ImageTextAlternativeUI', () => {
7878
} );
7979

8080
it( 'should set alt attribute value to textarea and select it', () => {
81-
const spy = sinon.spy( form.labeledInput, 'select' );
81+
const spy = sinon.spy( form.labeledInput.fieldView, 'select' );
8282

8383
setData( model, '[<image src="" alt="foo bar"></image>]' );
8484

8585
button.fire( 'execute' );
8686
sinon.assert.calledOnce( spy );
87-
expect( form.labeledInput.value ).equals( 'foo bar' );
87+
expect( form.labeledInput.fieldView.value ).equals( 'foo bar' );
8888
} );
8989

9090
it( 'should set empty text to textarea and select it when there is no alt attribute', () => {
91-
const spy = sinon.spy( form.labeledInput, 'select' );
91+
const spy = sinon.spy( form.labeledInput.fieldView, 'select' );
9292

9393
setData( model, '[<image src=""></image>]' );
9494

9595
button.fire( 'execute' );
9696
sinon.assert.calledOnce( spy );
97-
expect( form.labeledInput.value ).equals( '' );
97+
expect( form.labeledInput.fieldView.value ).equals( '' );
9898
} );
9999
} );
100100

101101
describe( 'balloon panel form', () => {
102102
// https://github.com/ckeditor/ckeditor5-image/issues/114
103103
it( 'should make sure the input always stays in sync with the value of the command', () => {
104104
const button = editor.ui.componentFactory.create( 'imageTextAlternative' );
105-
106105
// Mock the value of the input after some past editing.
107-
form.labeledInput.value = 'foo';
106+
form.labeledInput.fieldView.value = 'foo';
108107

109108
// Mock the user using the form, changing the value but clicking "Cancel".
110109
// so the command's value is not updated.
111-
form.labeledInput.inputView.element.value = 'This value was canceled.';
110+
form.labeledInput.fieldView.element.value = 'This value was canceled.';
112111

113112
// Mock the user editing the same image once again.
114113
setData( model, '[<image src="" alt="foo"></image>]' );
115114

116115
button.fire( 'execute' );
117-
expect( form.labeledInput.inputView.element.value ).to.equal( 'foo' );
116+
expect( form.labeledInput.fieldView.element.value ).to.equal( 'foo' );
118117
} );
119118

120119
it( 'should execute command on submit', () => {
@@ -123,7 +122,7 @@ describe( 'ImageTextAlternativeUI', () => {
123122

124123
sinon.assert.calledOnce( spy );
125124
sinon.assert.calledWithExactly( spy, 'imageTextAlternative', {
126-
newValue: form.labeledInput.inputView.element.value
125+
newValue: form.labeledInput.fieldView.element.value
127126
} );
128127
} );
129128

0 commit comments

Comments
 (0)