Skip to content

Commit

Permalink
Add CSP Nonce option to Select component
Browse files Browse the repository at this point in the history
Closes #2917
  • Loading branch information
Avaq committed Dec 7, 2018
1 parent 79efe79 commit 2bca4c9
Show file tree
Hide file tree
Showing 17 changed files with 6,345 additions and 80 deletions.
1 change: 1 addition & 0 deletions docs/pages/props/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function Api() {
selectOption: OptionType => void,
selectProps: any,
setValue: (ValueType, ActionTypes) => void,
emotion: any,
}
// passed as the second argument to \`onChange\`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"classnames": "^2.2.5",
"create-emotion": "^10.0.4",
"emotion": "^9.1.2",
"memoize-one": "^4.0.0",
"prop-types": "^15.6.0",
Expand Down
10 changes: 8 additions & 2 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { Component, type ElementRef, type Node } from 'react';

import memoizeOne from 'memoize-one';
import createEmotion from 'create-emotion';
import { MenuPlacer } from './components/Menu';
import isEqual from './internal/react-fast-compare';

Expand Down Expand Up @@ -242,6 +243,8 @@ export type Props = {
tabSelectsValue: boolean,
/* The value of the select; reflected by the selected option */
value: ValueType,
/* A CSP Nonce which will be used in injected style sheets */
nonce?: string
};

export const defaultProps = {
Expand Down Expand Up @@ -369,6 +372,8 @@ export default class Select extends Component<Props, State> {
const selectValue = cleanValue(value);
const menuOptions = this.buildMenuOptions(props, selectValue);

this.emotion = createEmotion(props.nonce ? { nonce: props.nonce } : {});

this.state.menuOptions = menuOptions;
this.state.selectValue = selectValue;
}
Expand Down Expand Up @@ -721,6 +726,7 @@ export default class Select extends Component<Props, State> {
setValue,
selectProps: props,
theme: this.getTheme(),
emotion: this.emotion
};
}

Expand Down Expand Up @@ -1427,8 +1433,8 @@ export default class Select extends Component<Props, State> {

if (!this.hasValue() || !controlShouldRenderValue) {
return inputValue ? null : (
<Placeholder
{...commonProps}
<Placeholder
{...commonProps}
key="placeholder"
isDisabled={isDisabled}
isFocused={isFocused}
Expand Down
2,919 changes: 2,918 additions & 1 deletion src/__tests__/__snapshots__/Async.test.js.snap

Large diffs are not rendered by default.

2,919 changes: 2,918 additions & 1 deletion src/__tests__/__snapshots__/AsyncCreatable.test.js.snap

Large diffs are not rendered by default.

Loading

0 comments on commit 2bca4c9

Please sign in to comment.