Skip to content

Create SLDSButton test file and remove aria-live on button component #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/SLDSButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class Button extends React.Component {
return (
<button className={this.getClassName()} {...props} onClick={click}>

<span aria-live="assertive">{this.props.iconPosition === 'right' ? this.props.label : null}</span>
<span>{this.props.iconPosition === 'right' ? this.props.label : null}</span>

{this.renderIcon()}

<span aria-live="assertive">{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}</span>
<span>{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}</span>

</button>
);
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/HomePage/ButtonSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = React.createClass( {
</PrismCode>
<div className='slds-p-vertical--large'>
<SLDSButton
label='Test Button'
label='Test'
variant='neutral'
iconName='download'
iconSize='small'
Expand Down
78 changes: 71 additions & 7 deletions lib/SLDSButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var _utilsCreateChainedFunction = require('../utils/create-chained-function');

var _utilsCreateChainedFunction2 = _interopRequireDefault(_utilsCreateChainedFunction);

var _SLDSIconsJs = require('../SLDSIcons.js');

var _lodash = require('lodash');

var classNames = require('classnames');
Expand All @@ -44,10 +46,22 @@ var Button = (function (_React$Component) {
_classCallCheck(this, Button);

_get(Object.getPrototypeOf(Button.prototype), 'constructor', this).call(this, props);
this.state = {};
this.state = { active: false };
}

_createClass(Button, [{
key: 'componentWillMount',
value: function componentWillMount() {
/*===============================
TODO: refactor so that React doesn't throw warnings in console
for (var key in this.props) {
if(this.props.hasOwnProperty(key) && typeof(this.props[key]) === 'string' && key !== 'label'){
this.props[key] = this.props[key].toLowerCase();
}
}
===============================*/
}
}, {
key: 'onClick',
value: function onClick(e) {
this.setState({ active: !this.state.active });
Expand All @@ -57,22 +71,72 @@ var Button = (function (_React$Component) {
value: function getClassName() {
var _classNames;

return classNames(this.props.className, 'slds-button', (_classNames = {}, _defineProperty(_classNames, 'slds-button--' + this.props.flavor, this.props.flavor), _defineProperty(_classNames, 'slds-is-selected', this.state.active), _classNames));
var isStateful = this.props.stateful && this.state.active ? true : false;
return classNames(this.props.className, 'slds-button', (_classNames = {}, _defineProperty(_classNames, 'slds-button--' + this.props.variant, this.props.variant), _defineProperty(_classNames, 'slds-is-selected', isStateful), _classNames));
}
}, {
key: 'renderIcon',
value: function renderIcon() {
if (this.props.iconName) {
return _react2['default'].createElement(_SLDSIconsJs.ButtonIcon, {
name: this.props.iconName,
size: this.props.iconSize,
position: this.props.iconPosition || 'left' });
}
}
}, {
key: 'render',
value: function render() {
var props = (0, _lodash.omit)('className', this.props);
var click = (0, _utilsCreateChainedFunction2['default'])(this.props.onClick, this.onClick.bind(this));
return _react2['default'].createElement(
'button',
_extends({ className: this.getClassName() }, props, { onClick: click }),
this.props.children
);

//If the button is only an icon render this:
if (this.props.variant === 'icon') {
return _react2['default'].createElement(
'button',
_extends({ className: this.getClassName() }, props, { onClick: click }),
_react2['default'].createElement(_SLDSIconsJs.Icon, {
name: this.props.iconName,
category: 'utility',
size: this.props.iconSize,
className: 'slds-icon' }),
_react2['default'].createElement(
'span',
{ className: 'slds-assistive-text' },
this.props.label
)
);
}
//Else we assume the button has a visible label (with or without an icon):
else {
return _react2['default'].createElement(
'button',
_extends({ className: this.getClassName() }, props, { onClick: click }),
_react2['default'].createElement(
'span',
{ 'aria-live': 'assertive' },
this.props.iconPosition === 'right' ? this.props.label : null
),
this.renderIcon(),
_react2['default'].createElement(
'span',
{ 'aria-live': 'assertive' },
this.props.iconPosition === 'left' || !this.props.iconPosition ? this.props.label : null
)
);
}
}
}]);

return Button;
})(_react2['default'].Component);

Button.propTypes = {
label: _react2['default'].PropTypes.string.isRequired,
variant: _react2['default'].PropTypes.oneOf(['base', 'neutral', 'brand', 'icon']),
iconName: _react2['default'].PropTypes.string,
iconSize: _react2['default'].PropTypes.oneOf(['x-small', 'small', 'medium', 'large']),
iconPosition: _react2['default'].PropTypes.oneOf(['left', 'right'])
};

module.exports = Button;
4 changes: 2 additions & 2 deletions lib/SLDSIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ var ButtonIcon = _react2['default'].createClass({
getDefaultProps: function getDefaultProps() {

return {
category: 'utility'
};
category: 'utility' };
},

// Utility Icon Reference: https://www.lightningdesignsystem.com/resources/icons#utility
render: function render() {

var useTag = '<use xlink:href="' + _SLDSSettings2['default'].getAssetsPath() + '/icons/' + this.props.category + '-sprite/svg/symbols.svg#' + this.props.name + '" />';
Expand Down
121 changes: 121 additions & 0 deletions lib/SLDSLookup/Menu/Item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _SLDSIcons = require("../../../SLDSIcons");

var _utils = require('../../../utils');

var Item = (function (_React$Component) {
_inherits(Item, _React$Component);

function Item(props) {
_classCallCheck(this, Item);

_get(Object.getPrototypeOf(Item.prototype), 'constructor', this).call(this, props);
}

_createClass(Item, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.isActive !== this.props.isActive && nextProps.isActive === true) {
this.scrollFocus();
this.props.setFocus(this.props.id);
}
}
}, {
key: 'boldSearchText',
value: function boldSearchText(children) {
var term = this.props.searchTerm;
if (!children || !term) return children;
var regex = new RegExp('(' + term + ')', 'gi');
return _react2['default'].Children.map(children, function (c) {
return typeof c === 'string' ? _react2['default'].createElement('span', { dangerouslySetInnerHTML: { __html: c.replace(regex, '<mark>$1</mark>') } }) : c;
});
}
}, {
key: 'handleClick',
value: function handleClick(e) {
e.preventDefault();
if (e.nativeEvent) {
e.nativeEvent.preventDefault();
e.nativeEvent.stopImmediatePropagation();
}
return this.props.onSelect(this.props.id);
}
}, {
key: 'scrollFocus',
value: function scrollFocus() {
var height = _react2['default'].findDOMNode(this).offsetHeight;
if (height && this.props.handleItemFocus) {
this.props.handleItemFocus(this.props.index, height);
}
}
}, {
key: 'render',
value: function render() {
var className = 'slds-lookup__item';
var id = this.props.id;
if (this.props.isActive) className += ' slds-theme--shade';

return(
//IMPORTANT: anchor id is used to set lookup's input's aria-activedescendant
_react2['default'].createElement(
'li',
{
className: className,
role: 'presentaion' },
_react2['default'].createElement(
'a',
{
href: this.props.href,
id: id,
tabIndex: '-1',
'aria-disabled': this.props.disabled,
role: 'option',
onClick: this.handleClick.bind(this),
onMouseDown: this.handleClick.bind(this) },
_react2['default'].createElement(_SLDSIcons.Icon, { name: 'account' }),
this.boldSearchText(this.props.children.label)
)
)
);
}
}]);

return Item;
})(_react2['default'].Component);

Item.propTypes = {
id: _react2['default'].PropTypes.string,
setFocus: _react2['default'].PropTypes.func,
scrollFocus: _react2['default'].PropTypes.func,
isActive: _react2['default'].PropTypes.bool,
onSelect: _react2['default'].PropTypes.func,
searchTerm: _react2['default'].PropTypes.string
};

Item.defaultProps = {};

module.exports = Item;
122 changes: 122 additions & 0 deletions lib/SLDSLookup/Menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _SLDSIcons = require("../../SLDSIcons");

var _utils = require('../../utils');

var _Item = require('./Item');

var _Item2 = _interopRequireDefault(_Item);

var Menu = (function (_React$Component) {
_inherits(Menu, _React$Component);

function Menu(props) {
_classCallCheck(this, Menu);

_get(Object.getPrototypeOf(Menu.prototype), 'constructor', this).call(this, props);
this.state = {};
}

_createClass(Menu, [{
key: 'componentDidUpdate',
value: function componentDidUpdate() {
var list = _react2['default'].findDOMNode(this.refs.list).children.length;
this.props.getListLength(list);
}
}, {
key: 'filter',
value: function filter(item) {
return this.props.filterWith(this.props.searchTerm, item);
}
}, {
key: 'handleItemFocus',
value: function handleItemFocus(itemIndex, itemHeight) {
if (this.refs.list) {
_react2['default'].findDOMNode(this.refs.list).scrollTop = itemIndex * itemHeight;
}
}
}, {
key: 'renderItems',
value: function renderItems() {
var _this = this;

return this.props.items.filter(this.filter, this).map(function (c, i) {
//isActive means it is aria-activedescendant
var isActive = _this.props.focusIndex === i ? true : false;
return _react2['default'].createElement(
_Item2['default'],
{
key: c.id,
id: c.id,
index: i,
setFocus: _this.props.setFocus,
isActive: isActive,
handleItemFocus: _this.handleItemFocus.bind(_this),
onSelect: _this.props.onSelect,
searchTerm: _this.props.searchTerm },
c
);
});
}
}, {
key: 'render',
value: function render() {
return _react2['default'].createElement(
'div',
{
className: 'ignore-react-onclickoutside slds-lookup__menu',
role: 'listbox',
ref: 'scroll' },
_react2['default'].createElement(
'ul',
{ className: 'slds-lookup__list',
role: 'presentation',
ref: 'list' },
this.renderItems()
)
);
}
}]);

return Menu;
})(_react2['default'].Component);

Menu.propTypes = {
searchTerm: _react2['default'].PropTypes.string,
filterWith: _react2['default'].PropTypes.func,
onSelect: _react2['default'].PropTypes.func,
label: _react2['default'].PropTypes.string,
items: _react2['default'].PropTypes.array,
setFocus: _react2['default'].PropTypes.func,
getListLength: _react2['default'].PropTypes.func,
listLength: _react2['default'].PropTypes.number,
focusIndex: _react2['default'].PropTypes.number
};

Menu.defaultProps = {};

module.exports = Menu;
Loading