diff --git a/vizro-core/changelog.d/20240126_162059_amward_use_label.md b/vizro-core/changelog.d/20240126_162059_amward_use_label.md new file mode 100644 index 000000000..ea79f9cc6 --- /dev/null +++ b/vizro-core/changelog.d/20240126_162059_amward_use_label.md @@ -0,0 +1,47 @@ + + + + + + +### Changed + +- Replaced `html.P` with `html.Label` in form components. ([#293](https://github.com/mckinsey/vizro/pull/293)) + + + + diff --git a/vizro-core/src/vizro/models/_components/form/_user_input.py b/vizro-core/src/vizro/models/_components/form/_user_input.py index 2f74fd80a..161850f2a 100644 --- a/vizro-core/src/vizro/models/_components/form/_user_input.py +++ b/vizro-core/src/vizro/models/_components/form/_user_input.py @@ -40,7 +40,7 @@ class UserInput(VizroBaseModel): def build(self): return html.Div( [ - html.P(self.title) if self.title else None, + html.Label(self.title, htmlFor=self.id) if self.title else None, dbc.Input( id=self.id, placeholder=self.placeholder, diff --git a/vizro-core/src/vizro/models/_components/form/checklist.py b/vizro-core/src/vizro/models/_components/form/checklist.py index 4be346041..982244cf8 100644 --- a/vizro-core/src/vizro/models/_components/form/checklist.py +++ b/vizro-core/src/vizro/models/_components/form/checklist.py @@ -45,7 +45,7 @@ def build(self): return html.Div( [ - html.P(self.title) if self.title else None, + html.Label(self.title, htmlFor=self.id) if self.title else None, dcc.Checklist( id=self.id, options=full_options, diff --git a/vizro-core/src/vizro/models/_components/form/dropdown.py b/vizro-core/src/vizro/models/_components/form/dropdown.py index 5df9d580f..1ff5bf169 100755 --- a/vizro-core/src/vizro/models/_components/form/dropdown.py +++ b/vizro-core/src/vizro/models/_components/form/dropdown.py @@ -57,7 +57,7 @@ def build(self): full_options, default_value = get_options_and_default(options=self.options, multi=self.multi) return html.Div( [ - html.P(self.title) if self.title else None, + html.Label(self.title, htmlFor=self.id) if self.title else None, dcc.Dropdown( id=self.id, options=full_options, diff --git a/vizro-core/src/vizro/models/_components/form/radio_items.py b/vizro-core/src/vizro/models/_components/form/radio_items.py index 07569c3c2..76bbbc384 100644 --- a/vizro-core/src/vizro/models/_components/form/radio_items.py +++ b/vizro-core/src/vizro/models/_components/form/radio_items.py @@ -46,7 +46,7 @@ def build(self): return html.Div( [ - html.P(self.title) if self.title else None, + html.Label(self.title, htmlFor=self.id) if self.title else None, dcc.RadioItems( id=self.id, options=full_options, diff --git a/vizro-core/src/vizro/models/_components/form/range_slider.py b/vizro-core/src/vizro/models/_components/form/range_slider.py index 6db6c32c2..4f448910c 100644 --- a/vizro-core/src/vizro/models/_components/form/range_slider.py +++ b/vizro-core/src/vizro/models/_components/form/range_slider.py @@ -91,7 +91,7 @@ def build(self): "max": self.max, }, ), - html.P(self.title) if self.title else None, + html.Label(self.title, htmlFor=self.id) if self.title else None, html.Div( [ dcc.RangeSlider( diff --git a/vizro-core/src/vizro/models/_components/form/slider.py b/vizro-core/src/vizro/models/_components/form/slider.py index a999830d1..80a1a9354 100644 --- a/vizro-core/src/vizro/models/_components/form/slider.py +++ b/vizro-core/src/vizro/models/_components/form/slider.py @@ -87,7 +87,7 @@ def build(self): "max": self.max, }, ), - html.P(self.title) if self.title else None, + html.Label(self.title, htmlFor=self.id) if self.title else None, html.Div( [ dcc.Slider( diff --git a/vizro-core/src/vizro/static/css/typography.css b/vizro-core/src/vizro/static/css/typography.css index dbf14fb48..2a77a47f8 100644 --- a/vizro-core/src/vizro/static/css/typography.css +++ b/vizro-core/src/vizro/static/css/typography.css @@ -59,6 +59,7 @@ h4, } p, +label, .body-ui-02 { color: var(--text-secondary); font-size: var(--text-size-02); diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py b/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py index 30d47a737..18f966d92 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py @@ -132,7 +132,7 @@ def test_checklist_build(self): checklist = Checklist(id="checklist_id", options=["A", "B", "C"], title="Title").build() expected_checklist = html.Div( [ - html.P("Title"), + html.Label("Title", htmlFor="checklist_id"), dcc.Checklist( id="checklist_id", options=["ALL", "A", "B", "C"], diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py b/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py index be05fa380..870febc9d 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py @@ -155,7 +155,7 @@ def test_dropdown_with_all_option(self): ).build() expected_dropdown = html.Div( [ - html.P("Title"), + html.Label("Title", htmlFor="dropdown_id"), dcc.Dropdown( id="dropdown_id", options=["ALL", "A", "B", "C"], @@ -176,7 +176,7 @@ def test_dropdown_without_all_option(self): dropdown = Dropdown(id="dropdown_id", options=["A", "B", "C"], multi=False, title="Title").build() expected_dropdown = html.Div( [ - html.P("Title"), + html.Label("Title", htmlFor="dropdown_id"), dcc.Dropdown( id="dropdown_id", options=["A", "B", "C"], diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py b/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py index 6ee3f6a1b..91299fbe1 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py @@ -132,7 +132,7 @@ def test_radio_items_build(self): radio_items = RadioItems(id="radio_items_id", options=["A", "B", "C"], title="Title").build() expected_radio_items = html.Div( [ - html.P("Title"), + html.Label("Title", htmlFor="radio_items_id"), dcc.RadioItems( id="radio_items_id", options=["A", "B", "C"], diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py b/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py index ddc3677b6..574a01a4d 100644 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py @@ -90,7 +90,7 @@ def expected_range_slider_with_optional(): "max": 10, }, ), - html.P("Title"), + html.Label("Title", htmlFor="range_slider_with_all"), html.Div( [ dcc.RangeSlider( diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py b/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py index e55245d85..ba11f7b8f 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py @@ -24,7 +24,7 @@ def expected_slider(): "max": 10, }, ), - html.P("Test title"), + html.Label("Test title", htmlFor="slider_id"), html.Div( [ dcc.Slider(