Add No Results Row#272
Conversation
:no_results_attrs opt, add empty row|
@woylie This is a follow up from the previous discussion. I was reminded that CSS pseudo selectors can be used for this type of scenario, where we can't check a LiveStream for emptiness. Hat tip to @clarkware. 🤠 |
|
Thanks for opening this PR. I have a few thoughts to consider.
If we decide to stick with the original approach instead, encapsulating the condition in a named function could improve clarity: defp no_results?([]), do: true
defp no_results?(%LiveStream{inserts: []}), do: true
defp no_results?(_), do: falseHowever, the LiveStream struct is undocumented. I'm also not sure whether it is sufficient to just look at the An alternative could be adding an |
|
Thank you for the feedback, and sorry I didn't see your response earlier. There's a bit more complexity here than I expected, so please forgive the lengthy response below. CSS ClassesI could set a Conditional RenderingMy goal was to make this something the developer doesn't need to think about. I think conditionally rendering a While it's possible I had a wrong implementation, I believe I wasn't seeing the "No results" row when I used a similar approach that checked Existing PatternsRendering a It's not obvious what to do next. I completely understand wanting to keep the components CSS framework-agnostic, but we'd need to figure out where to put custom styles if this is going to be something devs don't need to think about. |
That's true, but the same is true for the Tailwind class if your project does not use Tailwind. It would be odd to have a class that's specific for one single framework. If we were to add this, I'd want to use a generic class name like
It depends on the situation, but if it's a paginated table where you replace the stream whenever you paginate, then you know whether there are results or not when you fetch the results. In that case, you could do something like: def handle_params(params, _, socket) do
{items, meta} = list_items(params)
{:noreply, socket |> assign(:empty?, items == []) |> stream(items, replace: true)}
endThis doesn't work in an infinite scroll or more-button scenario where you keep adding items without removing the old ones, of course.
I don't think we can do anything with aria attributes about this. Here are some examples about how screen readers announce tables: https://a11y-101.com/development/tables. Screen readers would always see and announce the table. We cannot conditionally add aria attributes to part of the table, since it's a CSS based solution. Side note, I just found that WCAG suggests to use |
Description
When a Flop table has no rows in the table body, there is no messaging about empty contents. Although,
:no_results_contentis listed as an option, it appears to have no impact on the UI.This PR adds a
:no_results_attrsoption and a new<tr>that is rendered when there are no@items. This solution works with both lists and LiveStreams.Checklist