react-widgets
Version:
An à la carte set of polished, extensible, and accessible inputs built for React
80 lines (57 loc) • 2.27 kB
JavaScript
;
var babelHelpers = require('../util/babelHelpers.js');
exports.__esModule = true;
var _react = require('react');
var _react2 = babelHelpers.interopRequireDefault(_react);
var _utilCompat = require('../util/compat');
var _utilCompat2 = babelHelpers.interopRequireDefault(_utilCompat);
var shape = _react2['default'].PropTypes.shape({
//setActive: React.PropTypes.func,
reconcile: _react2['default'].PropTypes.func
});
function defaultReconcile(key, id) {
return id;
}
function flushAriaToNode(id, nodeOrComponent, ctx) {
var node = typeof nodeOrComponent === 'function' ? nodeOrComponent(ctx) : typeof nodeOrComponent === 'string' ? ctx.refs[nodeOrComponent] : ctx;
if (node) {
if (id) _utilCompat2['default'].findDOMNode(node).setAttribute('aria-activedescendant', id);else _utilCompat2['default'].findDOMNode(node).removeAttribute('aria-activedescendant');
}
}
exports['default'] = function (nodeOrComponent) {
var reconcileChildren = arguments.length <= 1 || arguments[1] === undefined ? defaultReconcile : arguments[1];
return {
propTypes: {
ariaActiveDescendantKey: _react2['default'].PropTypes.string.isRequired
},
contextTypes: {
activeDescendants: shape
},
childContextTypes: {
activeDescendants: shape
},
ariaActiveDescendant: function ariaActiveDescendant(id) {
var key = arguments.length <= 1 || arguments[1] === undefined ? this.props.ariaActiveDescendantKey : arguments[1];
var activeDescendants = this.context.activeDescendants;
var current = this.__ariaActiveDescendantId;
if (id === undefined) return current;
id = reconcileChildren.call(this, key, id);
if (id === undefined) id = current;else {
this.__ariaActiveDescendantId = id;
flushAriaToNode(id, nodeOrComponent, this);
}
activeDescendants && activeDescendants.reconcile(key, id);
},
getChildContext: function getChildContext() {
var _this = this;
return this._context || (this._context = {
activeDescendants: {
reconcile: function reconcile(key, id) {
return _this.ariaActiveDescendant(id, key);
}
}
});
}
};
};
module.exports = exports['default'];