Skip to content

Commit 1d93f7d

Browse files
fix(types): allow non-object src in OnCopyProps (#211)
* fix(types): allow non-object src in OnCopyProps The enableClipboard callback receives the value of the copied entry, so src can be a string, number, boolean or null. It was typed as object, which made typeof narrowing on src resolve to never. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(types): include undefined in OnCopyProps src Entries whose value is undefined render a copy icon too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1dcdcfe commit 1d93f7d

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎index.d.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ export interface ReactJsonViewProps {
175175

176176
export interface OnCopyProps {
177177
/**
178-
* The JSON tree source object
178+
* The value of the copied entry.
179179
*/
180-
src: object
180+
src: object | string | number | boolean | null | undefined
181181
/**
182182
* List of keys.
183183
*/

‎test/tests/js/components/CopyToClipboard-test.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { expect } from 'chai'
44

55
import CopyToClipboard from './../../../../src/js/components/CopyToClipboard'
66

7-
function copyToClipboard (src) {
7+
function copyToClipboard (src, clickCallback) {
88
const copied = []
99
const { clipboard } = global.navigator
1010

@@ -20,6 +20,7 @@ function copyToClipboard (src) {
2020
src={src}
2121
namespace={['root']}
2222
theme='rjv-default'
23+
clickCallback={clickCallback}
2324
hidden={false}
2425
/>
2526
)
@@ -96,4 +97,12 @@ describe('<CopyToClipboard />', function () {
9697
it('CopyToClipboard copies a regexp as source text', function () {
9798
expect(copyToClipboard(/pattern/g)).to.deep.equal(['/pattern/g'])
9899
})
100+
101+
it('CopyToClipboard passes a string value to clickCallback as src', function () {
102+
const calls = []
103+
copyToClipboard('a string', copy => calls.push(copy))
104+
expect(calls).to.deep.equal([
105+
{ src: 'a string', namespace: ['root'], name: 'root' }
106+
])
107+
})
99108
})

0 commit comments

Comments
 (0)