Skip to content

Commit 3baaad2

Browse files
chore(AutoComplete): fix NoResultItem contrast ratio (#3957)
Co-authored-by: primer-css <primer-css@users.noreply.github.com>
1 parent 26f29b4 commit 3baaad2

6 files changed

Lines changed: 65 additions & 73 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/view-components": patch
3+
---
4+
5+
chore(AutoComplete): fix NoResultItem contrast ratio
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
module Primer
1+
# frozen_string_literal: true
2+
3+
module Primer
24
module Beta
35
class AutoComplete
4-
class NoResultItem < Item
6+
# Use `NoResultItem` to display a message when no autocomplete results are found.
7+
# Renders as a simple div inside the overlay, not as a list item.
8+
class NoResultItem < Primer::Component
9+
status :beta
10+
11+
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
512
def initialize(**system_arguments)
6-
super(
7-
role: :presentation,
8-
aria: merge_aria(
9-
{ aria: { hidden: true } },
10-
system_arguments
11-
),
12-
value: "",
13-
disabled: true,
14-
'data-no-result-found': true,
15-
**system_arguments
13+
@system_arguments = deny_tag_argument(**system_arguments)
14+
@system_arguments[:tag] = :div
15+
@system_arguments[:"data-no-result-found"] = true
16+
@system_arguments[:"aria-hidden"] = true
17+
18+
@system_arguments[:classes] = class_names(
19+
"p-2",
20+
"color-fg-muted",
21+
system_arguments[:classes]
1622
)
1723
end
24+
25+
def call
26+
render(Primer::BaseComponent.new(**@system_arguments)) { content }
27+
end
1828
end
1929
end
2030
end
21-
end
31+
end

static/arguments.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3904,7 +3904,14 @@
39043904
"short_name": "AutoCompleteNoResultItem",
39053905
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/beta/auto_complete/no_result_item.rb",
39063906
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/beta/auto_complete/no_result_item/default/",
3907-
"parameters": []
3907+
"parameters": [
3908+
{
3909+
"name": "system_arguments",
3910+
"type": "Hash",
3911+
"default": "N/A",
3912+
"description": "[System arguments](/system-arguments)"
3913+
}
3914+
]
39083915
},
39093916
{
39103917
"component": "Avatar",

static/info_arch.json

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11879,6 +11879,32 @@
1187911879
}
1188011880
],
1188111881
"subcomponents": [
11882+
{
11883+
"fully_qualified_name": "Primer::Beta::AutoComplete::NoResultItem",
11884+
"description": "Use `NoResultItem` to display a message when no autocomplete results are found.\nRenders as a simple div inside the overlay, not as a list item.",
11885+
"accessibility_docs": null,
11886+
"is_form_component": false,
11887+
"is_published": true,
11888+
"requires_js": false,
11889+
"component": "AutoComplete::NoResultItem",
11890+
"status": "beta",
11891+
"a11y_reviewed": false,
11892+
"short_name": "AutoCompleteNoResultItem",
11893+
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/beta/auto_complete/no_result_item.rb",
11894+
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/beta/auto_complete/no_result_item/default/",
11895+
"parameters": [
11896+
{
11897+
"name": "system_arguments",
11898+
"type": "Hash",
11899+
"default": "N/A",
11900+
"description": "{{link_to_system_arguments_docs}}"
11901+
}
11902+
],
11903+
"slots": [],
11904+
"methods": [],
11905+
"previews": [],
11906+
"subcomponents": []
11907+
},
1188211908
{
1188311909
"fully_qualified_name": "Primer::Beta::AutoComplete::Item",
1188411910
"description": "Use `AutoCompleteItem` to list results of an auto-completed search.",
@@ -11971,62 +11997,6 @@
1197111997
"methods": [],
1197211998
"previews": [],
1197311999
"subcomponents": []
11974-
},
11975-
{
11976-
"fully_qualified_name": "Primer::Beta::AutoComplete::NoResultItem",
11977-
"description": "",
11978-
"accessibility_docs": null,
11979-
"is_form_component": false,
11980-
"is_published": true,
11981-
"requires_js": false,
11982-
"component": "AutoComplete::NoResultItem",
11983-
"status": "beta",
11984-
"a11y_reviewed": false,
11985-
"short_name": "AutoCompleteNoResultItem",
11986-
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/beta/auto_complete/no_result_item.rb",
11987-
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/beta/auto_complete/no_result_item/default/",
11988-
"parameters": [],
11989-
"slots": [
11990-
{
11991-
"name": "leading_visual",
11992-
"description": "The leading visual rendered before the link.",
11993-
"parameters": [
11994-
{
11995-
"name": "kwargs",
11996-
"type": "Hash",
11997-
"default": "N/A",
11998-
"description": "The arguments accepted by {{#link_to_component}}Primer::Beta::Avatar{{/link_to_component}} or {{#link_to_component}}Primer::Beta::Octicon{{/link_to_component}}"
11999-
}
12000-
]
12001-
},
12002-
{
12003-
"name": "trailing_visual",
12004-
"description": "The trailing visual rendered after the link.",
12005-
"parameters": [
12006-
{
12007-
"name": "kwargs",
12008-
"type": "Hash",
12009-
"default": "N/A",
12010-
"description": "The arguments accepted by {{#link_to_component}}Primer::Beta::Octicon{{/link_to_component}}, {{#link_to_component}}Primer::Beta::Label{{/link_to_component}}, or {{#link_to_component}}Primer::Beta::Counter{{/link_to_component}}"
12011-
}
12012-
]
12013-
},
12014-
{
12015-
"name": "description",
12016-
"description": "Optional description",
12017-
"parameters": [
12018-
{
12019-
"name": "system_arguments",
12020-
"type": "Hash",
12021-
"default": "N/A",
12022-
"description": "{{link_to_system_arguments_docs}}"
12023-
}
12024-
]
12025-
}
12026-
],
12027-
"methods": [],
12028-
"previews": [],
12029-
"subcomponents": []
1203012000
}
1203112001
]
1203212002
},

test/components/beta/auto_complete/item_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ def test_renders_with_inline_description
9191
end
9292

9393
def test_renders_no_results
94-
render_inline(Primer::Beta::AutoComplete::NoResultItem.new(value: "", )) do |component|
94+
render_inline(Primer::Beta::AutoComplete::NoResultItem.new) do
9595
"No results"
9696
end
9797

98-
assert_selector("[role=\"presentation\"][data-autocomplete-value=\"\"][aria-disabled=\"true\"].ActionListItem", text: "No results")
98+
assert_selector("div[data-no-result-found][aria-hidden=\"true\"]", text: "No results")
9999
end
100100
end

test/components/component_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PrimerComponentTest < Minitest::Test
4343
end],
4444
[Primer::Alpha::AutoComplete, { label_text: "Fruits", src: "Foo", list_id: "Bar", input_id: "input-id", input_name: "input-name" }],
4545
[Primer::Alpha::AutoComplete::Item, { value: "Foo" }],
46-
[Primer::Beta::AutoComplete::NoResultItem, { value: "Foo" }],
46+
[Primer::Beta::AutoComplete::NoResultItem, {}],
4747
[Primer::Beta::AutoComplete, { label_text: "Fruits", src: "Foo", list_id: "Bar", input_id: "input-id", input_name: "input-name" }],
4848
[Primer::Beta::AutoComplete::Item, { value: "Foo" }],
4949
[Primer::Beta::Avatar, { alt: "github", src: "https://github.com/github.png" }],

0 commit comments

Comments
 (0)