@atlaskit/form
Version:
A form allows people to input information.
25 lines (22 loc) • 775 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getFirstErrorField = void 0;
var _finalForm = require("final-form");
var getFirstErrorField = exports.getFirstErrorField = function getFirstErrorField(inputs, errors) {
// Guaranteed to be of type HTMLInputElement[] due to getInputs function overrided in createDecorator
var htmlInputs = inputs;
return htmlInputs.find(function (input) {
// If input is hidden, do not focus
if (input.type === 'hidden') {
return false;
}
// If input ID matches the error, focus
if (input.id && (0, _finalForm.getIn)(errors, input.id)) {
return true;
}
// Default to base behavior
return input.name && (0, _finalForm.getIn)(errors, input.name);
});
};