Tchanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277352
Change subject: Make increment buttons optional in number input widget
......................................................................
Make increment buttons optional in number input widget
Make configuration option for showing the plus and
minus buttons in a number input widget. (Show them
by default.)
Bug: T129318
Change-Id: I91401a681fcfa1aa929514a2a90b5bbc8616b9fb
---
M src/widgets/NumberInputWidget.js
1 file changed, 41 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/52/277352/1
diff --git a/src/widgets/NumberInputWidget.js b/src/widgets/NumberInputWidget.js
index 49e4c3f..603a63c 100644
--- a/src/widgets/NumberInputWidget.js
+++ b/src/widgets/NumberInputWidget.js
@@ -26,6 +26,7 @@
* @cfg {number} [max=Infinity] Maximum allowed value
* @cfg {number} [step=1] Delta when using the buttons or up/down arrow keys
* @cfg {number|null} [pageStep] Delta when using the page-up/page-down keys.
Defaults to 10 times #step.
+ * @cfg {boolean} [showButtons=true] Whether to show the plus and minus
buttons.
*/
OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) {
// Configuration initialization
@@ -34,7 +35,8 @@
min: -Infinity,
max: Infinity,
step: 1,
- pageStep: null
+ pageStep: null,
+ showButtons: true
}, config );
// Parent constructor
@@ -47,28 +49,30 @@
},
config.input
) );
- this.minusButton = new OO.ui.ButtonWidget( $.extend(
- {
- disabled: this.isDisabled(),
- tabIndex: -1
- },
- config.minusButton,
- {
- classes: [ 'oo-ui-numberInputWidget-minusButton' ],
- label: '−'
- }
- ) );
- this.plusButton = new OO.ui.ButtonWidget( $.extend(
- {
- disabled: this.isDisabled(),
- tabIndex: -1
- },
- config.plusButton,
- {
- classes: [ 'oo-ui-numberInputWidget-plusButton' ],
- label: '+'
- }
- ) );
+ if ( config.showButtons ) {
+ this.minusButton = new OO.ui.ButtonWidget( $.extend(
+ {
+ disabled: this.isDisabled(),
+ tabIndex: -1
+ },
+ config.minusButton,
+ {
+ classes: [
'oo-ui-numberInputWidget-minusButton' ],
+ label: '−'
+ }
+ ) );
+ this.plusButton = new OO.ui.ButtonWidget( $.extend(
+ {
+ disabled: this.isDisabled(),
+ tabIndex: -1
+ },
+ config.plusButton,
+ {
+ classes: [ 'oo-ui-numberInputWidget-plusButton'
],
+ label: '+'
+ }
+ ) );
+ }
// Events
this.input.connect( this, {
@@ -79,12 +83,14 @@
keydown: this.onKeyDown.bind( this ),
'wheel mousewheel DOMMouseScroll': this.onWheel.bind( this )
} );
- this.plusButton.connect( this, {
- click: [ 'onButtonClick', +1 ]
- } );
- this.minusButton.connect( this, {
- click: [ 'onButtonClick', -1 ]
- } );
+ if ( config.showButtons ) {
+ this.plusButton.connect( this, {
+ click: [ 'onButtonClick', +1 ]
+ } );
+ this.minusButton.connect( this, {
+ click: [ 'onButtonClick', -1 ]
+ } );
+ }
// Initialization
this.setIsInteger( !!config.isInteger );
@@ -92,11 +98,12 @@
this.setStep( config.step, config.pageStep );
this.$field = $( '<div>' ).addClass( 'oo-ui-numberInputWidget-field' )
- .append(
- this.minusButton.$element,
- this.input.$element,
- this.plusButton.$element
- );
+ .append( this.input.$element );
+ if ( config.showButtons ) {
+ this.$field
+ .prepend( this.minusButton.$element )
+ .append( this.plusButton.$element );
+ }
this.$element.addClass( 'oo-ui-numberInputWidget' ).append( this.$field
);
this.input.setValidation( this.validateNumber.bind( this ) );
};
--
To view, visit https://gerrit.wikimedia.org/r/277352
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I91401a681fcfa1aa929514a2a90b5bbc8616b9fb
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Tchanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits