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

Commit bc00c8b

Browse files
authored
Merge pull request #96 from ckeditor/i/6110
Other: Replaced `LabeledInputView` with `LabeledFieldView`. See ckeditor/ckeditor5#6110.
2 parents 581c84b + 2500cc4 commit bc00c8b

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

src/mediaembedui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ export default class MediaEmbedUI extends Plugin {
7878
// invisible form/input cannot be focused/selected.
7979
button.on( 'open', () => {
8080
// Make sure that each time the panel shows up, the URL field remains in sync with the value of
81-
// the command. If the user typed in the input, then canceled (`urlInputView#value` stays
81+
// the command. If the user typed in the input, then canceled (`urlInputView#fieldView#value` stays
8282
// unaltered) and re-opened it without changing the value of the media command (e.g. because they
8383
// didn't change the selection), they would see the old value instead of the actual value of the
8484
// command.
8585
form.url = command.value || '';
86-
form.urlInputView.select();
86+
form.urlInputView.fieldView.select();
8787
form.focus();
8888
}, { priority: 'low' } );
8989

src/ui/mediaformview.js

Lines changed: 12 additions & 11 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 FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
@@ -59,7 +60,7 @@ export default class MediaFormView extends View {
5960
/**
6061
* The URL input view.
6162
*
62-
* @member {module:ui/labeledinput/labeledinputview~LabeledInputView}
63+
* @member {module:ui/labeledfield/labeledfieldview~LabeledFieldView}
6364
*/
6465
this.urlInputView = this._createUrlInput();
6566

@@ -212,7 +213,7 @@ export default class MediaFormView extends View {
212213
* @type {Number}
213214
*/
214215
get url() {
215-
return this.urlInputView.inputView.element.value.trim();
216+
return this.urlInputView.fieldView.element.value.trim();
216217
}
217218

218219
/**
@@ -224,7 +225,7 @@ export default class MediaFormView extends View {
224225
* @param {String} url
225226
*/
226227
set url( url ) {
227-
this.urlInputView.inputView.element.value = url.trim();
228+
this.urlInputView.fieldView.element.value = url.trim();
228229
}
229230

230231
/**
@@ -265,24 +266,24 @@ export default class MediaFormView extends View {
265266
* Creates a labeled input view.
266267
*
267268
* @private
268-
* @returns {module:ui/labeledinput/labeledinputview~LabeledInputView} Labeled input view instance.
269+
* @returns {module:ui/labeledfield/labeledfieldview~LabeledFieldView} Labeled input view instance.
269270
*/
270271
_createUrlInput() {
271272
const t = this.locale.t;
272273

273-
const labeledInput = new LabeledInputView( this.locale, InputTextView );
274-
const inputView = labeledInput.inputView;
274+
const labeledInput = new LabeledFieldView( this.locale, createLabeledInputText );
275+
const inputField = labeledInput.fieldView;
275276

276277
this._urlInputViewInfoDefault = t( 'Paste the media URL in the input.' );
277278
this._urlInputViewInfoTip = t( 'Tip: Paste the URL into the content to embed faster.' );
278279

279280
labeledInput.label = t( 'Media URL' );
280281
labeledInput.infoText = this._urlInputViewInfoDefault;
281-
inputView.placeholder = 'https://example.com';
282+
inputField.placeholder = 'https://example.com';
282283

283-
inputView.on( 'input', () => {
284+
inputField.on( 'input', () => {
284285
// Display the tip text only when there's some value. Otherwise fall back to the default info text.
285-
labeledInput.infoText = inputView.element.value ? this._urlInputViewInfoTip : this._urlInputViewInfoDefault;
286+
labeledInput.infoText = inputField.element.value ? this._urlInputViewInfoTip : this._urlInputViewInfoDefault;
286287
} );
287288

288289
return labeledInput;

tests/mediaembedui.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe( 'MediaEmbedUI', () => {
8484
describe( '#open event', () => {
8585
it( 'executes the actions with the "low" priority', () => {
8686
const spy = sinon.spy();
87-
const selectSpy = sinon.spy( form.urlInputView, 'select' );
87+
const selectSpy = sinon.spy( form.urlInputView.fieldView, 'select' );
8888

8989
button.on( 'open', () => {
9090
spy();
@@ -106,7 +106,7 @@ describe( 'MediaEmbedUI', () => {
106106
} );
107107

108108
it( 'should select the content of the input', () => {
109-
const spy = sinon.spy( form.urlInputView, 'select' );
109+
const spy = sinon.spy( form.urlInputView.fieldView, 'select' );
110110

111111
button.fire( 'open' );
112112
sinon.assert.calledOnce( spy );

tests/ui/mediaformview.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,21 @@ describe( 'MediaFormView', () => {
7979

8080
describe( 'url input view', () => {
8181
it( 'has placeholder', () => {
82-
expect( view.urlInputView.inputView.placeholder ).to.equal( 'https://example.com' );
82+
expect( view.urlInputView.fieldView.placeholder ).to.equal( 'https://example.com' );
8383
} );
8484

8585
it( 'has info text', () => {
8686
expect( view.urlInputView.infoText ).to.match( /^Paste the media URL/ );
8787
} );
8888

8989
it( 'displays the tip upon #input when the field has a value', () => {
90-
view.urlInputView.inputView.element.value = 'foo';
91-
view.urlInputView.inputView.fire( 'input' );
90+
view.urlInputView.fieldView.element.value = 'foo';
91+
view.urlInputView.fieldView.fire( 'input' );
9292

9393
expect( view.urlInputView.infoText ).to.match( /^Tip: Paste the URL into/ );
9494

95-
view.urlInputView.inputView.element.value = '';
96-
view.urlInputView.inputView.fire( 'input' );
95+
view.urlInputView.fieldView.element.value = '';
96+
view.urlInputView.fieldView.fire( 'input' );
9797

9898
expect( view.urlInputView.infoText ).to.match( /^Paste the media URL/ );
9999
} );
@@ -243,19 +243,19 @@ describe( 'MediaFormView', () => {
243243

244244
describe( 'url()', () => {
245245
it( 'returns the #inputView DOM value', () => {
246-
view.urlInputView.inputView.element.value = 'foo';
246+
view.urlInputView.fieldView.element.value = 'foo';
247247

248248
expect( view.url ).to.equal( 'foo' );
249249
} );
250250

251251
it( 'sets the #inputView DOM value', () => {
252-
view.urlInputView.inputView.element.value = 'bar';
252+
view.urlInputView.fieldView.element.value = 'bar';
253253

254254
view.url = 'foo';
255-
expect( view.urlInputView.inputView.element.value ).to.equal( 'foo' );
255+
expect( view.urlInputView.fieldView.element.value ).to.equal( 'foo' );
256256

257257
view.url = ' baz ';
258-
expect( view.urlInputView.inputView.element.value ).to.equal( 'baz' );
258+
expect( view.urlInputView.fieldView.element.value ).to.equal( 'baz' );
259259
} );
260260
} );
261261

0 commit comments

Comments
 (0)