mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-11 08:43:02 +00:00
Cleanup for linting issues, and added last bit of focus handling for … (#304)
* Cleanup for linting issues, and added last bit of focus handling for selected modifications and specials * added correct value for selectedRefId for utility slot section menu when Empty All selected
This commit is contained in:
@@ -43,13 +43,13 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
this._rollBest = this._rollBest.bind(this);
|
this._rollBest = this._rollBest.bind(this);
|
||||||
this._rollWorst = this._rollWorst.bind(this);
|
this._rollWorst = this._rollWorst.bind(this);
|
||||||
this._reset = this._reset.bind(this);
|
this._reset = this._reset.bind(this);
|
||||||
|
|
||||||
this._keyDown = this._keyDown.bind(this);
|
this._keyDown = this._keyDown.bind(this);
|
||||||
|
|
||||||
this.modItems = [];// Array to hold various element refs (<li>, <div>, <ul>, etc.)
|
this.modItems = [];// Array to hold various element refs (<li>, <div>, <ul>, etc.)
|
||||||
this.firstModId = null;
|
this.firstModId = null;
|
||||||
this.firstBPLabel = null;// First item in mod menu
|
this.firstBPLabel = null;// First item in mod menu
|
||||||
this.lastModId = null;
|
this.lastModId = null;
|
||||||
|
this.selectedModId = null;
|
||||||
|
this.selectedSpecialId = null;
|
||||||
this.lastNeId = null;// Last number editor id. Used to set focus to last number editor when shift-tab pressed on first element in mod menu.
|
this.lastNeId = null;// Last number editor id. Used to set focus to last number editor when shift-tab pressed on first element in mod menu.
|
||||||
this.modValDidChange = false; // used to determine if component update was caused by change in modification value.
|
this.modValDidChange = false; // used to determine if component update was caused by change in modification value.
|
||||||
this._handleModChange = this._handleModChange.bind(this);
|
this._handleModChange = this._handleModChange.bind(this);
|
||||||
@@ -83,8 +83,7 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
const close = this._blueprintSelected.bind(this, blueprintName, grade);
|
const close = this._blueprintSelected.bind(this, blueprintName, grade);
|
||||||
const key = blueprintName + ':' + grade;
|
const key = blueprintName + ':' + grade;
|
||||||
const tooltipContent = blueprintTooltip(translate, blueprint.grades[grade], Modifications.modules[m.grp].blueprints[blueprintName].grades[grade].engineers, m.grp);
|
const tooltipContent = blueprintTooltip(translate, blueprint.grades[grade], Modifications.modules[m.grp].blueprints[blueprintName].grades[grade].engineers, m.grp);
|
||||||
|
if (classes.indexOf('active') >= 0) this.selectedModId = key;
|
||||||
|
|
||||||
blueprintGrades.unshift(<li key={key} tabIndex="0" data-id={key} className={classes} style={{ width: '2em' }} onMouseOver={termtip.bind(null, tooltipContent)} onMouseOut={tooltip.bind(null, null)} onClick={close} onKeyDown={this._keyDown} ref={modItem => this.modItems[key] = modItem}>{grade}</li>);
|
blueprintGrades.unshift(<li key={key} tabIndex="0" data-id={key} className={classes} style={{ width: '2em' }} onMouseOver={termtip.bind(null, tooltipContent)} onMouseOut={tooltip.bind(null, null)} onClick={close} onKeyDown={this._keyDown} ref={modItem => this.modItems[key] = modItem}>{grade}</li>);
|
||||||
}
|
}
|
||||||
if (blueprintGrades) {
|
if (blueprintGrades) {
|
||||||
@@ -178,6 +177,7 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
const classes = cn('button-inline-menu', {
|
const classes = cn('button-inline-menu', {
|
||||||
active: m.blueprint && m.blueprint.special && m.blueprint.special.edname == specialName
|
active: m.blueprint && m.blueprint.special && m.blueprint.special.edname == specialName
|
||||||
});
|
});
|
||||||
|
if (classes.indexOf('active') >= 0) this.selectedSpecialId = specialName;
|
||||||
const close = this._specialSelected.bind(this, specialName);
|
const close = this._specialSelected.bind(this, specialName);
|
||||||
if (m.blueprint && m.blueprint.name) {
|
if (m.blueprint && m.blueprint.name) {
|
||||||
let tmp = {};
|
let tmp = {};
|
||||||
@@ -324,6 +324,8 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
const { m, ship } = this.props;
|
const { m, ship } = this.props;
|
||||||
ship.clearModifications(m);
|
ship.clearModifications(m);
|
||||||
ship.clearModuleBlueprint(m);
|
ship.clearModuleBlueprint(m);
|
||||||
|
this.selectedModId = null;
|
||||||
|
this.selectedSpecialId = null;
|
||||||
this.props.onChange();
|
this.props.onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,6 +358,13 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
if (!this.modValDidChange) {
|
if (!this.modValDidChange) {
|
||||||
if (this.modItems['modMainDiv'].children.length > 0) {
|
if (this.modItems['modMainDiv'].children.length > 0) {
|
||||||
|
if (this.modItems[this.selectedModId]) {
|
||||||
|
this.modItems[this.selectedModId].focus();
|
||||||
|
return;
|
||||||
|
} else if (this.modItems[this.selectedSpecialId]) {
|
||||||
|
this.modItems[this.selectedSpecialId].focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
let firstEleCn = this.modItems['modMainDiv'].children[0].className;
|
let firstEleCn = this.modItems['modMainDiv'].children[0].className;
|
||||||
if (firstEleCn.indexOf('button-inline-menu') >= 0) {
|
if (firstEleCn.indexOf('button-inline-menu') >= 0) {
|
||||||
this.modItems['modMainDiv'].firstElementChild.focus();
|
this.modItems['modMainDiv'].firstElementChild.focus();
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ class TextInputBox extends React.Component {
|
|||||||
type:'number',
|
type:'number',
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
inputValue: this.props.percent * this.props.max
|
inputValue: this.props.percent * this.props.max
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -339,6 +339,7 @@ class TextInputBox extends React.Component {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the value in the text box
|
* Get the value in the text box
|
||||||
|
* @returns {number} inputValue Value of the input box
|
||||||
*/
|
*/
|
||||||
_getValue() {
|
_getValue() {
|
||||||
return this.state.inputValue;
|
return this.state.inputValue;
|
||||||
@@ -348,7 +349,7 @@ class TextInputBox extends React.Component {
|
|||||||
* values depending on what user
|
* values depending on what user
|
||||||
* has selected
|
* has selected
|
||||||
*
|
*
|
||||||
* @param {SyntheticEvent} event
|
* @param {SyntheticEvent} event ReactJs onChange event
|
||||||
*/
|
*/
|
||||||
_handleChange(event) {
|
_handleChange(event) {
|
||||||
if (event.target.value < 0) {
|
if (event.target.value < 0) {
|
||||||
@@ -373,9 +374,13 @@ class TextInputBox extends React.Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get the value in the text box
|
||||||
|
* @return {React.Component} Text Input component for Slider
|
||||||
|
*/
|
||||||
render() {
|
render() {
|
||||||
let { axisUnit, onChange, percent, scale } = this.props;
|
let { axisUnit, onChange, percent, scale } = this.props;
|
||||||
return <div style={this.state.divStyle}><input style={this.state.inputStyle} value={this._getValue()} min={this.state.min} max={this.props.max} onChange={this._handleChange} onKeyUp={this._keyup} tabIndex={this.state.tabIndex} maxLength={this.state.maxLength} size={this.state.size} onBlur={() => {this._handleBlur()}} onFocus={() => {this._handleFocus()}} type={this.state.type} ref={(ip) => this.sliderVal = ip}/><text className="primary upp" style={this.state.labelStyle}>{this.props.axisUnit}</text></div>;
|
return <div style={this.state.divStyle}><input style={this.state.inputStyle} value={this._getValue()} min={this.state.min} max={this.props.max} onChange={this._handleChange} onKeyUp={this._keyup} tabIndex={this.state.tabIndex} maxLength={this.state.maxLength} size={this.state.size} onBlur={() => {this._handleBlur();}} onFocus={() => {this._handleFocus();}} type={this.state.type} ref={(ip) => this.sliderVal = ip}/><text className="primary upp" style={this.state.labelStyle}>{this.props.axisUnit}</text></div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export default class UtilitySlotSection extends SlotSection {
|
|||||||
* Empty all utility slots and close the menu
|
* Empty all utility slots and close the menu
|
||||||
*/
|
*/
|
||||||
_empty() {
|
_empty() {
|
||||||
|
this.selectedRefId = this.firstRefId;
|
||||||
this.props.ship.emptyUtility();
|
this.props.ship.emptyUtility();
|
||||||
this.props.onChange();
|
this.props.onChange();
|
||||||
this._close();
|
this._close();
|
||||||
|
|||||||
Reference in New Issue
Block a user