Skip to content

Conversation

@Sakthieswaran-tech
Copy link
Contributor

  1. Introduced pattern and patternError options in InputConfig
  2. Added real-time pattern validation on keypress and submit
  3. Updated demo and tests to cover pattern validation flow

@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@31fc3ad). Learn more about missing BASE report.

Files with missing lines Patch % Lines
packages/input/src/index.ts 87.50% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1862   +/-   ##
=======================================
  Coverage        ?   95.63%           
=======================================
  Files           ?       45           
  Lines           ?     2818           
  Branches        ?      749           
=======================================
  Hits            ?     2695           
  Misses          ?      114           
  Partials        ?        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Sakthieswaran-tech
Copy link
Contributor Author

I removed the demo for this feature because the e2e build test fails whenever the config object is modified and used inside the demo package. Since the functionality is already covered through detailed test cases, I have removed the demo to keep the CI build stable. Let me know if any changes are required.

README.md Outdated
@@ -1 +1 @@
packages/prompts/README.md
packages/prompts/README.md
Copy link
Owner

Choose a reason for hiding this comment

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

What changed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was automatically added by the linter when I ran yarn eslint --write . it only inserted a blank line, no actual content change.

Comment on lines 61 to 68
if (pattern && !pattern.test(answer)) {
setError(patternError || 'Invalid input update');
setStatus('idle');
return;
}
const isValid =
required && !answer ? 'You must provide a value' : await validate(answer);
if (isValid === true) {
Copy link
Owner

Choose a reason for hiding this comment

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

There's a question of which validation should occur first when both are present... This open 2 questions:

  • Should we allow both to be set or not?
  • If we do allow both, which should run first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, I chose to run the pattern check first when both pattern and validate are present. The idea is that pattern acts as a lightweight, immediate constraint on the input format, while validate can still handle deeper validations afterward.

Since a pattern error would already be shown live during typing, re-overriding that message on Enter didn’t feel right, it’s clearer UX to surface the existing pattern feedback first and only run validate once the pattern passes.

if (pattern && !pattern.test(answer)) {
setError(patternError || 'Invalid input update');
setStatus('idle');
return;
Copy link
Owner

Choose a reason for hiding this comment

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

Let's not use an early return and loop the validation within the rest of the logical flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the early return and integrated the pattern validation within the existing logical flow to keep it consistent with the rest of the validation logic.

Comment on lines 88 to 93
setValue(newValue);
if (pattern && !pattern.test(newValue)) {
setError(patternError || 'Invalid input');
} else {
setError(undefined);
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need this here, wouldn't that case hit the default else case down there, which does the same logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I removed the redundant pattern check since the default else block already performs the same validation for keypress updates.

@Sakthieswaran-tech Sakthieswaran-tech force-pushed the feat/input-pattern-validation branch from dd200cb to cad8455 Compare October 27, 2025 07:14
@Sakthieswaran-tech Sakthieswaran-tech force-pushed the feat/input-pattern-validation branch from cad8455 to 68e76d1 Compare October 27, 2025 07:28
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.

2 participants