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

Reverting portal disable functionality, causing clipping behavior. #1461

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/young-clocks-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/math-input": patch
"@khanacademy/perseus": patch
---

Reverting portal disabled functionality to ensure no clipping behavior.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ exports[`keypad should snapshot expanded: first render 1`] = `
aria-disabled="false"
aria-label="Numbers"
aria-selected="true"
class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-focused_en8zhl-o_O-clickable_1ncqa8p"
class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-clickable_1ncqa8p"
role="tab"
tabindex="0"
type="button"
>
<div
class="default_xu2jcg-o_O-base_1pupywz-o_O-focused_2hwz1v"
class="default_xu2jcg-o_O-base_1pupywz"
>
<div
class="default_xu2jcg-o_O-innerBox_qdbgl3"
Expand Down Expand Up @@ -1075,13 +1075,13 @@ exports[`keypad should snapshot unexpanded: first render 1`] = `
aria-disabled="false"
aria-label="Numbers"
aria-selected="true"
class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-focused_en8zhl-o_O-clickable_1ncqa8p"
class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-clickable_1ncqa8p"
role="tab"
tabindex="0"
type="button"
>
<div
class="default_xu2jcg-o_O-base_1pupywz-o_O-focused_2hwz1v"
class="default_xu2jcg-o_O-base_1pupywz"
>
<div
class="default_xu2jcg-o_O-innerBox_qdbgl3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function V2KeypadWithMathquill() {
return (
<div style={{maxWidth: "400px", margin: "2em"}}>
<Popover
portal={false}
content={
<PopoverContentCore
style={{
Expand Down
20 changes: 18 additions & 2 deletions packages/math-input/src/components/tabbar/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,26 @@ function TabbarItem(props: TabItemProps): React.ReactElement {
const tabRef = useRef<{focus: () => void}>(null);

useEffect(() => {
let timeout;
if (role === "tab" && focus) {
// Move element into view when it is focused
tabRef?.current?.focus();
/**
* When tabs are within a WonderBlocks Popover component, the
* manner in which the component is rendered and moved causes
* focus to snap to the bottom of the page on first focus.
*
* This timeout moves around that by delaying the focus enough
* to wait for the WonderBlock Popover to move to the correct
* location and scroll the user to the correct location.
* */
timeout = setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the revert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I removed it because without the portal it was no longer necessary. Now that we're doing portaling again we need the timeout behavior.

if (tabRef?.current) {
// Move element into view when it is focused
tabRef?.current.focus();
}
}, 0);
}

return () => clearTimeout(timeout);
}, [role, focus, tabRef]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ describe("Perseus' MathInput", () => {
screen.getByRole("button", {name: /open math keypad/}),
);
await userEvent.tab(); // to "123" tab
await userEvent.tab(); // to "1" button
await userEvent.keyboard("{enter}");
act(() => jest.runOnlyPendingTimers());

Expand Down
1 change: 0 additions & 1 deletion packages/perseus/src/components/math-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ class InnerMathInput extends React.Component<InnerProps, State> {
<Popover
opened={this.state.keypadOpen}
onClose={() => this.closeKeypad()}
portal={false}
dismissEnabled
content={() => (
<PopoverContentCore
Expand Down