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

Commit

Permalink
Merge pull request #96 from ckeditor/i/6110
Browse files Browse the repository at this point in the history
Other: Replaced `LabeledInputView` with `LabeledFieldView`. See ckeditor/ckeditor5#6110.
  • Loading branch information
jodator authored Mar 26, 2020
2 parents 581c84b + 2500cc4 commit bc00c8b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/mediaembedui.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export default class MediaEmbedUI extends Plugin {
// invisible form/input cannot be focused/selected.
button.on( 'open', () => {
// Make sure that each time the panel shows up, the URL field remains in sync with the value of
// the command. If the user typed in the input, then canceled (`urlInputView#value` stays
// the command. If the user typed in the input, then canceled (`urlInputView#fieldView#value` stays
// unaltered) and re-opened it without changing the value of the media command (e.g. because they
// didn't change the selection), they would see the old value instead of the actual value of the
// command.
form.url = command.value || '';
form.urlInputView.select();
form.urlInputView.fieldView.select();
form.focus();
}, { priority: 'low' } );

Expand Down
23 changes: 12 additions & 11 deletions src/ui/mediaformview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import View from '@ckeditor/ckeditor5-ui/src/view';
import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';

import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import LabeledInputView from '@ckeditor/ckeditor5-ui/src/labeledinput/labeledinputview';
import InputTextView from '@ckeditor/ckeditor5-ui/src/inputtext/inputtextview';

import LabeledFieldView from '@ckeditor/ckeditor5-ui/src/labeledfield/labeledfieldview';
import { createLabeledInputText } from '@ckeditor/ckeditor5-ui/src/labeledfield/utils';

import submitHandler from '@ckeditor/ckeditor5-ui/src/bindings/submithandler';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
Expand Down Expand Up @@ -59,7 +60,7 @@ export default class MediaFormView extends View {
/**
* The URL input view.
*
* @member {module:ui/labeledinput/labeledinputview~LabeledInputView}
* @member {module:ui/labeledfield/labeledfieldview~LabeledFieldView}
*/
this.urlInputView = this._createUrlInput();

Expand Down Expand Up @@ -212,7 +213,7 @@ export default class MediaFormView extends View {
* @type {Number}
*/
get url() {
return this.urlInputView.inputView.element.value.trim();
return this.urlInputView.fieldView.element.value.trim();
}

/**
Expand All @@ -224,7 +225,7 @@ export default class MediaFormView extends View {
* @param {String} url
*/
set url( url ) {
this.urlInputView.inputView.element.value = url.trim();
this.urlInputView.fieldView.element.value = url.trim();
}

/**
Expand Down Expand Up @@ -265,24 +266,24 @@ export default class MediaFormView extends View {
* Creates a labeled input view.
*
* @private
* @returns {module:ui/labeledinput/labeledinputview~LabeledInputView} Labeled input view instance.
* @returns {module:ui/labeledfield/labeledfieldview~LabeledFieldView} Labeled input view instance.
*/
_createUrlInput() {
const t = this.locale.t;

const labeledInput = new LabeledInputView( this.locale, InputTextView );
const inputView = labeledInput.inputView;
const labeledInput = new LabeledFieldView( this.locale, createLabeledInputText );
const inputField = labeledInput.fieldView;

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

labeledInput.label = t( 'Media URL' );
labeledInput.infoText = this._urlInputViewInfoDefault;
inputView.placeholder = 'https://example.com';
inputField.placeholder = 'https://example.com';

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

return labeledInput;
Expand Down
4 changes: 2 additions & 2 deletions tests/mediaembedui.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe( 'MediaEmbedUI', () => {
describe( '#open event', () => {
it( 'executes the actions with the "low" priority', () => {
const spy = sinon.spy();
const selectSpy = sinon.spy( form.urlInputView, 'select' );
const selectSpy = sinon.spy( form.urlInputView.fieldView, 'select' );

button.on( 'open', () => {
spy();
Expand All @@ -106,7 +106,7 @@ describe( 'MediaEmbedUI', () => {
} );

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

button.fire( 'open' );
sinon.assert.calledOnce( spy );
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/mediaformview.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ describe( 'MediaFormView', () => {

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

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

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

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

view.urlInputView.inputView.element.value = '';
view.urlInputView.inputView.fire( 'input' );
view.urlInputView.fieldView.element.value = '';
view.urlInputView.fieldView.fire( 'input' );

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

describe( 'url()', () => {
it( 'returns the #inputView DOM value', () => {
view.urlInputView.inputView.element.value = 'foo';
view.urlInputView.fieldView.element.value = 'foo';

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

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

view.url = 'foo';
expect( view.urlInputView.inputView.element.value ).to.equal( 'foo' );
expect( view.urlInputView.fieldView.element.value ).to.equal( 'foo' );

view.url = ' baz ';
expect( view.urlInputView.inputView.element.value ).to.equal( 'baz' );
expect( view.urlInputView.fieldView.element.value ).to.equal( 'baz' );
} );
} );

Expand Down

0 comments on commit bc00c8b

Please sign in to comment.