Skip to content

Commit

Permalink
try using UniqueIDProvider to resolve snapshot errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielle Whyte committed Nov 18, 2024
1 parent c9b5740 commit 2c9d887
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ exports[`renderer snapshots correct answer: correct answer 1`] = `
>
<label
class="text_f1191h-o_O-LabelLarge_5s82ln"
for="uid-dropdown-widget-1-wb-id"
for="uid-dropdown-widget-1-dropdown"
>
Test visible label
</label>
Expand All @@ -371,7 +371,7 @@ exports[`renderer snapshots correct answer: correct answer 1`] = `
aria-haspopup="listbox"
aria-label="Test ARIA label"
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_3ie67y"
id="uid-dropdown-widget-1-wb-id"
id="uid-dropdown-widget-1-dropdown"
type="button"
>
<span
Expand Down Expand Up @@ -427,7 +427,7 @@ exports[`renderer snapshots incorrect answer: incorrect answer 1`] = `
>
<label
class="text_f1191h-o_O-LabelLarge_5s82ln"
for="uid-dropdown-widget-2-wb-id"
for="uid-dropdown-widget-2-dropdown"
>
Test visible label
</label>
Expand All @@ -448,7 +448,7 @@ exports[`renderer snapshots incorrect answer: incorrect answer 1`] = `
aria-haspopup="listbox"
aria-label="Test ARIA label"
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_3ie67y"
id="uid-dropdown-widget-2-wb-id"
id="uid-dropdown-widget-2-dropdown"
type="button"
>
<span
Expand Down Expand Up @@ -504,7 +504,7 @@ exports[`renderer snapshots initial render: initial render 1`] = `
>
<label
class="text_f1191h-o_O-LabelLarge_5s82ln"
for="uid-dropdown-widget-0-wb-id"
for="uid-dropdown-widget-0-dropdown"
>
Test visible label
</label>
Expand All @@ -525,7 +525,7 @@ exports[`renderer snapshots initial render: initial render 1`] = `
aria-haspopup="listbox"
aria-label="Test ARIA label"
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_3ie67y"
id="uid-dropdown-widget-0-wb-id"
id="uid-dropdown-widget-0-dropdown"
type="button"
>
<span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`Dropdown widget should snapshot when opened: dropdown open 1`] = `
>
<label
class="text_f1191h-o_O-LabelLarge_5s82ln"
for="uid-dropdown-widget-1-wb-id"
for="uid-dropdown-widget-1-dropdown"
>
Test visible label
</label>
Expand All @@ -44,7 +44,7 @@ exports[`Dropdown widget should snapshot when opened: dropdown open 1`] = `
aria-haspopup="listbox"
aria-label="Test ARIA label"
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_3ie67y"
id="uid-dropdown-widget-1-wb-id"
id="uid-dropdown-widget-1-dropdown"
type="button"
>
<span
Expand Down Expand Up @@ -100,7 +100,7 @@ exports[`Dropdown widget should snapshot: initial render 1`] = `
>
<label
class="text_f1191h-o_O-LabelLarge_5s82ln"
for="uid-dropdown-widget-0-wb-id"
for="uid-dropdown-widget-0-dropdown"
>
Test visible label
</label>
Expand All @@ -121,7 +121,7 @@ exports[`Dropdown widget should snapshot: initial render 1`] = `
aria-haspopup="listbox"
aria-label="Test ARIA label"
class="button_vr44p2-o_O-shared_u51dsh-o_O-default_3ie67y"
id="uid-dropdown-widget-0-wb-id"
id="uid-dropdown-widget-0-dropdown"
type="button"
>
<span
Expand Down
15 changes: 9 additions & 6 deletions packages/perseus/src/widgets/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IDProvider, View} from "@khanacademy/wonder-blocks-core";
import {UniqueIDProvider, View} from "@khanacademy/wonder-blocks-core";
import {SingleSelect, OptionItem} from "@khanacademy/wonder-blocks-dropdown";
import {LabelLarge} from "@khanacademy/wonder-blocks-typography";
import * as React from "react";
Expand Down Expand Up @@ -82,8 +82,8 @@ class Dropdown extends React.Component<Props> implements Widget {
];

return (
<IDProvider scope={"dropdown-widget"}>
{(uniqueId) => (
<UniqueIDProvider scope="dropdown-widget" mockOnFirstRender={true}>
{(ids) => (
<View
// NOTE(jared): These are required to prevent weird behavior
// When there's a dropdown in a zoomable table.
Expand All @@ -95,12 +95,15 @@ class Dropdown extends React.Component<Props> implements Widget {
}}
>
{this.props.visibleLabel && (
<LabelLarge tag="label" htmlFor={uniqueId}>
<LabelLarge
tag="label"
htmlFor={ids.get("dropdown")}
>
{this.props.visibleLabel}
</LabelLarge>
)}
<SingleSelect
id={uniqueId}
id={ids.get("dropdown")}
placeholder=""
onChange={(value) =>
this._handleChange(parseInt(value))
Expand All @@ -113,7 +116,7 @@ class Dropdown extends React.Component<Props> implements Widget {
</SingleSelect>
</View>
)}
</IDProvider>
</UniqueIDProvider>
);
}
}
Expand Down

0 comments on commit 2c9d887

Please sign in to comment.