Skip to content

Commit

Permalink
fix(Popper): updated default of appendTo prop (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye authored Jul 10, 2024
1 parent 9ee53c9 commit 61a071c
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const warningRules = [
"overflowMenu-warn-updated-dropdownItem",
"pageSection-warn-variantClasses-applied",
"popover-warn-appendTo-default",
"popper-update-appendTo-default",
"react-dropzone-warn-upgrade",
"simpleFileUpload-warn-changes",
"sliderStep-warn-update-markup",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### popper-update-appendTo-default [(#10675)](https://github.com/patternfly/patternfly-react/pull/10675)

The default value of appendTo on Dropdown, Select, and Popper has been updated to `document.body`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const ruleTester = require("../../ruletester");
import * as rule from "./popper-update-appendTo-default";

ruleTester.run("popper-update-appendTo-default", rule, {
valid: [
{
code: `<Dropdown appendTo />`,
},
{
code: `import { Button } from '@patternfly/react-core';`,
},
],
invalid: [
{
code: `import { Dropdown } from '@patternfly/react-core';`,
output: `import { Dropdown } from '@patternfly/react-core';`,
errors: [
{
message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Dropdown as CustomThing } from '@patternfly/react-core';`,
output: `import { Dropdown as CustomThing } from '@patternfly/react-core';`,
errors: [
{
message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Select } from '@patternfly/react-core';`,
output: `import { Select } from '@patternfly/react-core';`,
errors: [
{
message: `The default value of appendTo on Select has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Popper } from '@patternfly/react-core';`,
output: `import { Popper } from '@patternfly/react-core';`,
errors: [
{
message: `The default value of appendTo on Popper has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Dropdown, Select, Popper, Button } from '@patternfly/react-core';`,
output: `import { Dropdown, Select, Popper, Button } from '@patternfly/react-core';`,
errors: [
{
message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
{
message: `The default value of appendTo on Select has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
{
message: `The default value of appendTo on Popper has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Dropdown } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js';`,
output: `import { Dropdown } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js';`,
errors: [
{
message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Dropdown } from '@patternfly/react-core/dist/js/components/Dropdown/index.js';`,
output: `import { Dropdown } from '@patternfly/react-core/dist/js/components/Dropdown/index.js';`,
errors: [
{
message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
{
code: `import { Dropdown } from '@patternfly/react-core/dist/dynamic/components/Dropdown/index.js';`,
output: `import { Dropdown } from '@patternfly/react-core/dist/dynamic/components/Dropdown/index.js';`,
errors: [
{
message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`,
type: "ImportSpecifier",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Rule } from "eslint";
import { ImportSpecifier } from "estree-jsx";
import { getFromPackage } from "../../helpers";

// https://github.com/patternfly/patternfly-react/pull/10675
module.exports = {
meta: {},
create: function (context: Rule.RuleContext) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const componentImports = imports.filter((specifier) =>
["Dropdown", "Select", "Popper"].includes(specifier.imported.name)
);

return !componentImports.length
? {}
: {
ImportSpecifier(node: ImportSpecifier) {
if (
componentImports
.map((imp) => imp.imported.name)
.includes(node.imported.name)
) {
context.report({
node,
message: `The default value of appendTo on ${node.imported.name} has been updated to \`document.body\`.`,
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Dropdown } from "@patternfly/react-core";

export const PopperUpdateAppendToDefaultInput = () => <Dropdown appendTo />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Dropdown } from "@patternfly/react-core";

export const PopperUpdateAppendToDefaultInput = () => <Dropdown appendTo />

0 comments on commit 61a071c

Please sign in to comment.