Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show missing required asterisk in BitDatePicker's label (#9862) #9880

Conversation

Cyrus-Sushiant
Copy link
Member

@Cyrus-Sushiant Cyrus-Sushiant commented Feb 12, 2025

This closes #9862

Summary by CodeRabbit

  • New Features

    • The DatePicker now supports a required field option, ensuring users must select a date when applicable.
    • Demo examples have been updated to demonstrate this new functionality.
  • Style

    • Visual enhancements include an asterisk indicator on required date picker labels for clearer user guidance.

Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

The pull request enhances the BitDatePicker component by enforcing required field validation. A new required="@Required" attribute is added to the input element, and corresponding conditional CSS classes are registered to visually indicate when the field is required. Additionally, a new CSS class is introduced to append an asterisk to the label. The demo files are updated to include examples of the new required functionality, ensuring the changes are demonstrated in practice without altering the existing logic.

Changes

File(s) Summary of Change
src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor
src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor.cs
Added the required="@Required" attribute to the input element and conditional CSS class registration to indicate required state when IsEnabled and Required are true.
src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.scss Introduced new CSS class .bit-dtp-req with nested styling for .bit-dtp-lbl::after to display an asterisk for required fields.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor.cs
Updated demo examples to include the new Required property for the BitDatePicker component, and added a new parameter in the demo class to showcase required validation.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant D as BitDatePicker Component
    participant S as Styling Logic
    participant F as Form Validator

    U->>D: Renders date picker with input field
    D->>S: Register CSS class if (IsEnabled && Required)
    U->>D: Interacts with input (enters date or leaves blank)
    U->>D: Submits form
    D->>F: Triggers built-in validation (required attribute)
    F-->>D: Returns validation result (error if empty)
Loading

Poem

Hop along in fields of code so bright,
I’m a rabbit with changes, leaping with delight.
A required star now shines on our date,
CSS magic adds flair, truly first-rate!
In demos and forms, the new path is laid,
CodeRabbit cheers as our code hops on its parade!
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (3)
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor (1)

22-23: Consider enhancing the Required demo with form validation.

While the basic demo shows how to set the Required attribute, it would be more helpful to demonstrate it within a form context showing validation behavior.

Consider adding validation example similar to the existing validation demo but specifically highlighting the Required functionality:

-<BitDatePicker Label="Required" Required />
+<EditForm Model="requiredModel" OnValidSubmit="HandleValidSubmit">
+    <DataAnnotationsValidator />
+    <BitDatePicker Label="Required Date" @bind-Value="requiredModel.Date" Required />
+    <ValidationMessage For="@(() => requiredModel.Date)" />
+    <BitButton ButtonType="BitButtonType.Submit">Submit</BitButton>
+</EditForm>
src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.scss (1)

750-756: LGTM! Consider enhancing screen reader support.

The implementation of the required field indicator is clean and follows the established patterns. The use of CSS variables and the spacing function maintains consistency.

Consider adding aria-hidden="true" to the asterisk and including "(required)" in the label text for better screen reader support:

 .bit-dtp-req {
     .bit-dtp-lbl::after {
         content: "*";
+        aria-hidden: true;
         color: $clr-req;
         margin-inline-start: spacing(0.625);
     }
+    .bit-dtp-lbl::before {
+        content: " (required)";
+        position: absolute;
+        width: 1px;
+        height: 1px;
+        padding: 0;
+        margin: -1px;
+        overflow: hidden;
+        clip: rect(0, 0, 0, 0);
+        white-space: nowrap;
+        border: 0;
+    }
 }
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor.cs (1)

1248-1253: Verify Required property integration with form validation.

The existing validation example uses the [Required] attribute. Consider adding another example that demonstrates how the Required property of BitDatePicker integrates with form validation to ensure they work together correctly.

Consider adding an example like this:

 <EditForm Model="validationModel" OnValidSubmit="HandleValidSubmit" OnInvalidSubmit="HandleInvalidSubmit">
     <DataAnnotationsValidator />
 
-    <BitDatePicker @bind-Value="validationModel.Date" />
+    <BitDatePicker @bind-Value="validationModel.Date" Required />
     <ValidationMessage For="@(() => validationModel.Date)" />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7edf0c and a0f8968.

📒 Files selected for processing (5)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor.cs (1 hunks)
  • src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.scss (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor (1 hunks)
  • src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build and test
🔇 Additional comments (3)
src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor (1)

37-37: LGTM! HTML5 required attribute properly implemented.

The required attribute is correctly bound to the Required parameter, enabling native HTML5 form validation.

src/BlazorUI/Bit.BlazorUI/Components/Inputs/_Pickers/DatePicker/BitDatePicker.razor.cs (1)

505-505: LGTM! CSS class registration properly implemented.

The CSS class registration correctly handles the required state by checking both IsEnabled and Required properties, following the component's established patterns.

src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/DatePicker/BitDatePickerDemo.razor.cs (1)

941-941: LGTM! Good example of the Required property.

The example clearly demonstrates how to use the Required property with the BitDatePicker component, which aligns with the PR's objective of fixing the required asterisk display issue.

@msynk msynk changed the title Fix show issue required asterisk in the label's BitDatePicker (#9862) Show missing required asterisk in BitDatePicker's label (#9862) Feb 12, 2025
@msynk msynk merged commit 58a192e into bitfoundation:develop Feb 12, 2025
2 of 3 checks passed
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.

Required asterisk missing BitDatePicker
2 participants