Skip to content

generate unique ids #347

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 10 commits into from
Jun 24, 2016
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
6 changes: 6 additions & 0 deletions components/button/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import omit from 'lodash.omit';

import { BUTTON } from '../../utilities/constants';

// ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';

const displayName = BUTTON;
const propTypes = {
/**
Expand Down Expand Up @@ -65,6 +70,7 @@ const propTypes = {
variant: React.PropTypes.oneOf(['base', 'neutral', 'brand', 'destructive', 'icon', 'inverse', 'icon-inverse'])
};
const defaultProps = {
id: shortid.generate(),
disabled: false,
hint: false,
iconSize: 'medium',
Expand Down
8 changes: 7 additions & 1 deletion components/card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import Empty from './empty';
// Removes the need for `PropTypes`.
const { PropTypes } = React;

// ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';

import { CARD } from '../../utilities/constants';

// Allow for predicatable DOM queries with `querySelectorAll(cssClasses.base)`
Expand Down Expand Up @@ -84,11 +89,12 @@ const Card = React.createClass({
/**
* Set the HTML `id` of the card. This also sets the `id` of the filter and the header actions.
*/
id: PropTypes.string.isRequired
id: PropTypes.string
},

getDefaultProps () {
return {
id: shortid.generate(),
heading: 'Related Items'
};
},
Expand Down
17 changes: 11 additions & 6 deletions components/data-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ### React
import React from 'react';

// ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';

// ### classNames
import classNames from 'classnames';

Expand All @@ -33,9 +38,6 @@ import isFunction from 'lodash.isfunction';
// ### reject
import reject from 'lodash.reject';

// ### uniqueId
import uniqueId from 'lodash.uniqueid';

// This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools)
import checkProps from './check-props';

Expand Down Expand Up @@ -86,12 +88,15 @@ const DataTable = React.createClass({
* Class names to be added to the table.
*/
className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
/**
* A unique ID is needed in order to support keyboard navigation and ARIA support.
*/
id: PropTypes.string,
/**
/**
* The collection of items to render in the table.
*/
items: PropTypes.array.isRequired,
/**
/**
* This function fires when the selection of rows changes.
*/
onChange: PropTypes.func,
Expand Down Expand Up @@ -124,7 +129,7 @@ const DataTable = React.createClass({
getDefaultProps () {
return {
bordered: false,
id: uniqueId(`${DATA_TABLE}-`),
id: shortid.generate(),
selection: [],
selectRows: false,
stacked: false,
Expand Down
11 changes: 8 additions & 3 deletions components/forms/checkbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import React from 'react';
// ### isFunction
import isFunction from 'lodash.isfunction';

// ### uniqueId
import uniqueId from 'lodash.uniqueid';
// ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';

// ### Event Helpers
import { KEYS, EventUtil } from '../../../utilities';
Expand Down Expand Up @@ -68,6 +70,9 @@ const Checkbox = React.createClass({
* Message to display when the Checkbox is in an error state. When this is present, also visually highlights the component as in error.
*/
errorText: React.PropTypes.string,
/**
* A unique ID is needed in order to support keyboard navigation and ARIA support.
*/
id: PropTypes.string,
/**
* An optional label for the Checkbox.
Expand All @@ -85,7 +90,7 @@ const Checkbox = React.createClass({

getDefaultProps () {
return {
id: uniqueId(`${FORMS_CHECKBOX}-`)
id: shortid.generate()
};
},

Expand Down
8 changes: 7 additions & 1 deletion components/forms/input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// React is an external dependency of the project.
import React from 'react';

// ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';

// ### classNames
// [github.com/JedWatson/classnames](https://github.com/JedWatson/classnames)
// This project uses `classnames`, "a simple javascript utility for conditionally
Expand Down Expand Up @@ -99,7 +104,7 @@ const Input = React.createClass({
/**
* Every input must have a unique ID in order to support keyboard navigation and ARIA support.
*/
id: PropTypes.string.isRequired,
id: PropTypes.string,
/**
* This label appears above the input.
*/
Expand Down Expand Up @@ -160,6 +165,7 @@ const Input = React.createClass({

getDefaultProps () {
return {
id: shortid.generate(),
iconPosition: 'left',
type: 'text'
};
Expand Down
2 changes: 1 addition & 1 deletion components/forms/input/inline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const InlineEdit = React.createClass({

handleBlur () {
if (!this.willSave) {
this.willSave = setTimeout(this.saveEdits, 100);
this.willSave = setTimeout(this.saveEdits, 200);
}
},

Expand Down
11 changes: 8 additions & 3 deletions components/menu-dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import ListItemLabel from "../menu-list/list-item-label";

import { MENU_DROPDOWN } from '../../utilities/constants';

// ### uniqueId
import uniqueId from 'lodash.uniqueid';
// ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';

const displayName = MENU_DROPDOWN;
const propTypes = {
Expand All @@ -43,6 +45,9 @@ const propTypes = {
* Delay on menu closing.
*/
hoverCloseDelay: React.PropTypes.number,
/**
* A unique ID is needed in order to support keyboard navigation and ARIA support.
*/
id: React.PropTypes.string,
label: React.PropTypes.string,
/**
Expand Down Expand Up @@ -74,7 +79,7 @@ const defaultProps = {
checkmark: false,
disabled: false,
hoverCloseDelay: 300,
id: uniqueId(`${MENU_DROPDOWN}-`),
id: shortid.generate(),
openOn: "click",
modal: true,
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@
"react-highlighter": "^0.3.2",
"react-modal": "^0.6.1",
"react-onclickoutside": "^4.5.0",
"shortid": "^2.2.6",
"tether": "1.1.0",
"tether-drop": "1.2.2",
"warning": "^2.1.0"
},
"devDependencies": {
"@kadira/storybook": "^1.27.0",
"@salesforce-ux/design-system": "git+ssh://[email protected]/salesforce-ux/design-system-internal.git#v2.1.0-beta.2-dist",
"@salesforce-ux/design-system": "git+ssh://[email protected]/salesforce-ux/design-system-internal.git#v2.1.0-beta.3-dist",
"@salesforce-ux/icons": "4.0.0",
"async": "^2.0.0-rc.5",
"babel": "^6.5.2",
Expand Down
5 changes: 0 additions & 5 deletions stories/forms/input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ storiesOf(FORMS_INPUT, module)
.addDecorator(getStory => <div className="slds-p-around--medium">{getStory()}</div>)
.add('Standard Input', () => (
<Input
id="unique-id-1"
label="Input Label"
placeholder="Placeholder Text"
/>
))
.add('Assistive Text, No Label', () => (
<Input
id="unique-id-1"
assistiveText="Assistive Text"
placeholder="Placeholder Text"
/>
))
.add('Input with Clickable Icon', () => (
<Input
id="unique-id-2"
label="Input Label"
iconName="close"
iconCategory="utility"
Expand All @@ -35,15 +32,13 @@ storiesOf(FORMS_INPUT, module)
))
.add('Read Only Input', () => (
<Input
id="unique-id-3"
label="Input Label"
readOnly
value="Read Only Value"
/>
))
.add('Required Input in Error State', () => (
<Input
id="unique-id-4"
label="Input Label"
required
errorText="Error Message"
Expand Down
25 changes: 0 additions & 25 deletions tests/input/input.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {

describe('SLDS INPUT **************************************************', () => {
const defaultProps = {
id: 'unique-id-2',
placeholder: 'Placeholder Text'
};

Expand Down Expand Up @@ -148,28 +147,4 @@ describe('SLDS INPUT **************************************************', () =>
expect(error.textContent).to.equal('Error Message');
});
});


// describe('Input with Clickable Icon', () => {
// let component;
// let input;
// let label;
// let icon;

// beforeEach(() => {
// component = getInput({ label: 'Input Label' });
// input = findRenderedDOMComponentWithTag(component, 'input');
// inputWrapper = findRenderedDOMComponentWithClass(component, 'slds-form-element__control');
// label = findRenderedDOMComponentWithClass(component, 'slds-form-element__label');
// icon = findRenderedDOMComponentWithTag(component, 'svg');
// });

// afterEach(() => {
// removeInput();
// });

// // input wrapper has class "slds-input-has-icon"
// // icon has class "slds-input__icon"
// // icon can be clicked (Simulate)
// });
});