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

Suggestion: Adding LiveView Classes to Improve Accessibility #131

Open
MonaAghili opened this issue Nov 22, 2024 · 0 comments
Open

Suggestion: Adding LiveView Classes to Improve Accessibility #131

MonaAghili opened this issue Nov 22, 2024 · 0 comments
Assignees
Milestone

Comments

@MonaAghili
Copy link
Member

MonaAghili commented Nov 22, 2024

https://hexdocs.pm/phoenix_live_view/bindings.html#loading-states-and-errors

Description:

The Phoenix LiveView phx- bindings allow you to dynamically modify styles, add styles, or show/hide elements or components based on user interactions. When a phx- event (e.g., phx-click) is triggered, LiveView temporarily applies unique classes like phx-click-loading to the targeted elements. This enables developers to easily control UI states without writing additional JavaScript.

For example, using [&.phx-click-loading], you can:

  1. Modify Styles Dynamically: Change backgrounds, opacity, or other CSS properties to indicate the element is in a "loading" state.

    <button 
      phx-click="start_process" 
      class="btn-primary [&.phx-click-loading]:bg-gray-400"
    >
      Submit
    </button>

    Here, the button changes its background to bg-gray-400 during the loading state.

  2. Show or Hide Components: Use this feature to toggle visibility of elements, such as loading spinners or tooltips.

    <div class="relative">
      <button phx-click="load_more" class="btn-primary">Load More</button>
      <div class="spinner [&.phx-click-loading]:block hidden"></div>
    </div>

    The spinner becomes visible (block) only when the phx-click-loading class is applied.

  3. Add Styles Dynamically: Use utility-based styles to disable buttons, change text color, or alter the cursor.

    <button 
      phx-click="save_data" 
      class="btn-primary [&.phx-click-loading]:cursor-wait [&.phx-click-loading]:opacity-50"
    >
      Save
    </button>

NOTE: This feature simplifies dynamic UI updates by leveraging classes applied during specific event states. It eliminates the need for JavaScript.

@MonaAghili MonaAghili added this to the 0.0.3 milestone Nov 22, 2024
@MonaAghili MonaAghili self-assigned this Nov 22, 2024
@MonaAghili MonaAghili changed the title Adding LiveView Classes to Improve Accessibility Suggestion: Adding LiveView Classes to Improve Accessibility Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant