Skip to content

Commit

Permalink
feat: added CSP nonce prop
Browse files Browse the repository at this point in the history
  • Loading branch information
dkremniov-bc committed Feb 27, 2024
1 parent c31c972 commit e67a114
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .yarn/versions/dd1eb89d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
releases:
"@radix-ui/react-scroll-area": patch
"@radix-ui/react-select": patch

declined:
- primitives
7 changes: 5 additions & 2 deletions packages/react/scroll-area/src/ScrollArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ ScrollArea.displayName = SCROLL_AREA_NAME;
const VIEWPORT_NAME = 'ScrollAreaViewport';

type ScrollAreaViewportElement = React.ElementRef<typeof Primitive.div>;
interface ScrollAreaViewportProps extends PrimitiveDivProps {}
interface ScrollAreaViewportProps extends PrimitiveDivProps {
nonce?: string;
}

const ScrollAreaViewport = React.forwardRef<ScrollAreaViewportElement, ScrollAreaViewportProps>(
(props: ScopedProps<ScrollAreaViewportProps>, forwardedRef) => {
const { __scopeScrollArea, children, ...viewportProps } = props;
const { __scopeScrollArea, children, nonce, ...viewportProps } = props;
const context = useScrollAreaContext(VIEWPORT_NAME, __scopeScrollArea);
const ref = React.useRef<ScrollAreaViewportElement>(null);
const composedRefs = useComposedRefs(forwardedRef, ref, context.onViewportChange);
Expand All @@ -151,6 +153,7 @@ const ScrollAreaViewport = React.forwardRef<ScrollAreaViewportElement, ScrollAre
dangerouslySetInnerHTML={{
__html: `[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}`,
}}
nonce={nonce}
/>
<Primitive.div
data-radix-scroll-area-viewport=""
Expand Down
7 changes: 5 additions & 2 deletions packages/react/select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1037,11 +1037,13 @@ const VIEWPORT_NAME = 'SelectViewport';

type SelectViewportElement = React.ElementRef<typeof Primitive.div>;
type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
interface SelectViewportProps extends PrimitiveDivProps {}
interface SelectViewportProps extends PrimitiveDivProps {
nonce?: string;
}

const SelectViewport = React.forwardRef<SelectViewportElement, SelectViewportProps>(
(props: ScopedProps<SelectViewportProps>, forwardedRef) => {
const { __scopeSelect, ...viewportProps } = props;
const { __scopeSelect, nonce, ...viewportProps } = props;
const contentContext = useSelectContentContext(VIEWPORT_NAME, __scopeSelect);
const viewportContext = useSelectViewportContext(VIEWPORT_NAME, __scopeSelect);
const composedRefs = useComposedRefs(forwardedRef, contentContext.onViewportChange);
Expand All @@ -1053,6 +1055,7 @@ const SelectViewport = React.forwardRef<SelectViewportElement, SelectViewportPro
dangerouslySetInnerHTML={{
__html: `[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`,
}}
nonce={nonce}
/>
<Collection.Slot scope={__scopeSelect}>
<Primitive.div
Expand Down

0 comments on commit e67a114

Please sign in to comment.