Skip to content

Conversation

@gautamkrishnar
Copy link
Contributor

@gautamkrishnar gautamkrishnar commented Dec 15, 2025

What: Closes #12178
This PR adds onBlur, onFocus, name and Id for input box configureable from the clipboardCopy component

Additional issues: n/a

Summary by CodeRabbit

  • New Features
    • Added inputId and inputName props plus onInputFocus and onInputBlur callbacks to ClipboardCopy to control/receive events from the internal input.
  • Tests
    • Added tests verifying id/name propagation to the internal input and that onInputFocus/onInputBlur fire appropriately (and don’t fire for unrelated inputs).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Walkthrough

ClipboardCopy now accepts new props: inputId, inputName, onInputFocus, and onInputBlur. inputId/inputName are forwarded to the internal TextInput (id defaults to text-input-${id} when not provided). onInputFocus/onInputBlur are forwarded as onFocus/onBlur handlers to the internal TextInput and are not passed to the wrapper. Tests verifying attribute propagation and focus/blur behavior were added.

Changes

Cohort / File(s) Summary
Component update
packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx
Added inputId and inputName to ClipboardCopyProps; added onInputFocus and onInputBlur props; destructured and forwarded id/name to TextInput (id={inputId ?? \text-input-${id}`}, name={inputName}) and wired onFocus={onInputFocus}/onBlur={onInputBlur}to theTextInput` while preventing these props from being passed to the container element.
Tests
packages/react-core/src/components/ClipboardCopy/__tests__/ClipboardCopy.test.tsx
Added tests asserting inputId/inputName propagate to the internal textbox and that onInputFocus/onInputBlur fire when the component's input receives/loses focus (and do not fire for unrelated native inputs).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review points:
    • Verify TypeScript prop types/signatures for inputId, inputName, onInputFocus, onInputBlur follow project conventions (including event parameter types).
    • Confirm forwarding uses the correct event objects and does not change existing props (onCopy, onChange).
    • Ensure id fallback (text-input-${id}) remains unique and consistent with prior behavior.
    • Validate tests simulate focus/blur robustly and are not environment-flaky.

Poem

🐰
I hopped along the keyboard trail, ears tuned to each small cue,
Now inputs know when I arrive and when I bid adieu,
A nibble of code, a twitch and cheer—focus, blur, and a copy too.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding callback props (onInputFocus, onInputBlur) and input-related props (inputId, inputName) to the ClipboardCopy component.
Linked Issues check ✅ Passed The PR implements the requirements from issue #12178 by exposing onBlur and onFocus callbacks, though the implementation uses onInputBlur/onInputFocus naming rather than the example's onBlur/onFocus.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the ClipboardCopy component: adding four new props (inputId, inputName, onInputFocus, onInputBlur) and corresponding tests without unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35512a5 and ad7d8f0.

⛔ Files ignored due to path filters (1)
  • packages/react-core/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopy.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx (5 hunks)
  • packages/react-core/src/components/ClipboardCopy/__tests__/ClipboardCopy.test.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build
  • GitHub Check: Build, test & deploy
🔇 Additional comments (5)
packages/react-core/src/components/ClipboardCopy/__tests__/ClipboardCopy.test.tsx (5)

312-316: LGTM!

Test correctly verifies that the inputId prop is forwarded to the internal TextInput element.


318-322: LGTM!

Test correctly verifies that the inputName prop is forwarded to the internal TextInput element.


353-362: LGTM!

Test correctly verifies that the onInputFocus handler fires when the ClipboardCopy textbox gains focus. The test pattern is consistent with existing event handler tests.


364-378: LGTM!

Test correctly verifies that the onInputFocus handler does not fire when focus moves to elements outside the ClipboardCopy component.


397-411: LGTM!

Test correctly verifies that the onInputBlur handler does not fire when the ClipboardCopy textbox is never focused.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx (1)

306-307: Document that these handlers only work for non-inline-compact variants.

The forwarding is correct, but note that onFocus and onBlur only work when variant is 'inline' or 'expansion' since the inline-compact variant doesn't use a TextInput component (it uses <span> or <code> elements instead).

Consider updating the JSDoc comments for these props to mention this limitation:

-  /** Callback function when text input is focused */
+  /** Callback function when text input is focused. Only applies to 'inline' and 'expansion' variants. */
   onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
-  /** Callback function when text input is blurred (focus leaves) */
+  /** Callback function when text input is blurred (focus leaves). Only applies to 'inline' and 'expansion' variants. */
   onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5053dd and a355381.

📒 Files selected for processing (1)
  • packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build, test & deploy
🔇 Additional comments (1)
packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx (1)

184-185: LGTM!

Correctly excludes the event handlers from the div props spread, ensuring they're only passed to the TextInput component.

Comment on lines 94 to 97
/** Callback function when text input is focused */
onFocus?: (event?: any) => void;
/** Callback function when text input is blurred (focus leaves) */
onBlur?: (event?: any) => void;
Copy link

@coderabbitai coderabbitai bot Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Use proper React event types instead of any.

The event parameter should use React.FocusEvent<HTMLInputElement> for type safety and consistency with React patterns, and the event should be required (not optional) as is standard for React event handlers.

Apply this diff to use proper typing:

-  /** Callback function when text input is focused */
-  onFocus?: (event?: any) => void;
-  /** Callback function when text input is blurred (focus leaves) */
-  onBlur?: (event?: any) => void;
+  /** Callback function when text input is focused */
+  onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
+  /** Callback function when text input is blurred (focus leaves) */
+  onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;

Note: This matches the pattern used for the onChange prop on line 93, which uses a specific React event type with a required event parameter.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** Callback function when text input is focused */
onFocus?: (event?: any) => void;
/** Callback function when text input is blurred (focus leaves) */
onBlur?: (event?: any) => void;
/** Callback function when text input is focused */
onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void;
/** Callback function when text input is blurred (focus leaves) */
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
🤖 Prompt for AI Agents
In packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx around
lines 94-97, replace the loose any event types with proper React focus event
types: change both onFocus and onBlur signatures to accept a required event
parameter typed as React.FocusEvent<HTMLInputElement> (e.g. onFocus?: (event:
React.FocusEvent<HTMLInputElement>) => void; and onBlur?: (event:
React.FocusEvent<HTMLInputElement>) => void;). Also ensure the React types are
available by importing React or the FocusEvent type from 'react' at the top of
the file if not already imported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the TextInput uses onFocus?: (event?: any) => void; and onBlur?: (event?: any) => void; do we need to update this?

We may need to fix the TextInput as well then.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the TextInput component file
fd -t f "TextInput" --extension tsx --extension ts | head -20

Length of output: 1571


🏁 Script executed:

#!/bin/bash
# Look at the TextInput component's prop definitions, specifically for onFocus and onBlur
ast-grep --pattern $'export interface TextInputProps $$$'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for the TextInput props interface definition
rg -nP --type=ts -A 50 "interface TextInputProps" | head -100

Length of output: 5359


@gautamkrishnar, you're absolutely correct! Looking at the TextInput component, it does define onFocus?: (event?: any) => void; and onBlur?: (event?: any) => void; (lines 84-86 in packages/react-core/src/components/TextInput/TextInput.tsx).

Since ClipboardCopy passes these props directly to TextInput (lines 275-276), they need to be type-compatible. If ClipboardCopy used stricter types like React.FocusEvent<HTMLInputElement>, there would be a TypeScript error when passing them through to TextInput.

For this PR, I recommend keeping the current event?: any types to maintain compatibility with TextInput and keep the scope focused on adding the callbacks functionality.

For a follow-up, it would be valuable to improve the TypeScript types across both components:

  • Update TextInput's onFocus and onBlur to use React.FocusEvent<HTMLInputElement>
  • Update ClipboardCopy to match
  • This ensures type safety throughout the component hierarchy

Would you like me to create a GitHub issue to track improving these event types in both TextInput and ClipboardCopy as a separate enhancement?


🧬 Code Graph Analysis Results

[ClipboardCopy.tsx]

  • File: packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx
  • Line range: around the onFocus/onBlur props in ClipboardCopyProps

Snippet:
/** Callback function when text input is focused /
onFocus?: (event?: any) => void;
/
* Callback function when text input is blurred (focus leaves) */
onBlur?: (event?: any) => void;

  • Purpose: Shows that ClipboardCopy currently defines onFocus/onBlur using event?: any, which is directly relevant to the user comment about TextInput onFocus/onBlur typings and potential need to align or fix typing there.

[TextInput.tsx]

  • File: packages/react-core/src/components/TextInput/TextInput.tsx
  • Line range: 252-254

Snippet:
export const TextInput = forwardRef((props: TextInputProps, ref: React.Ref) => (
<TextInputBase {...props} innerRef={ref as React.MutableRefObject} />
));

  • Purpose: Demonstrates how TextInput is exposed via forwardRef, which is relevant to type compatibility and potential adjustments needed in TextInput props (e.g., onFocus/onBlur typings) when used by ClipboardCopy.

@patternfly-build
Copy link
Collaborator

patternfly-build commented Dec 15, 2025

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit below, not blocking.

Also, would you mind adding some tests for these new props? We'd want to check that both callbacks aren't called when they shouldn't be, and that they are called when expected (so 4 tests total).

There's a couple tests for the onChange callback already in the test suite that you could use as a jumping off point.

@gautamkrishnar gautamkrishnar changed the title feat(ClipboardCopy): added onBlur and onFocus callbacks feat(ClipboardCopy): added textinput callbacks Dec 15, 2025
@gautamkrishnar gautamkrishnar marked this pull request as draft December 15, 2025 17:55
@gautamkrishnar gautamkrishnar changed the title feat(ClipboardCopy): added textinput callbacks feat(ClipboardCopy): added textinput callbacks and props Dec 15, 2025
@gautamkrishnar gautamkrishnar marked this pull request as ready for review December 15, 2025 18:03
@gautamkrishnar
Copy link
Contributor Author

Just updtaed the PR to include text input's id and name as well because it would be helpful in integrating with libraries like formik

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even get to request tests for the other new props you added 😿

(thank you for adding those in in addition to the other tests!)

@thatblindgeye thatblindgeye merged commit 4f5dcda into patternfly:main Dec 17, 2025
14 checks passed
@patternfly-build
Copy link
Collaborator

Your changes have been released in:

Thanks for your contribution! 🎉

@gautamkrishnar gautamkrishnar deleted the fix/12178 branch December 19, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ClipboardCopy] - expose input onBlur, onFocus event handlers and name, id for clipboard copy component input

4 participants