Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# dnn-modal backgroundDismiss obsolete
# dnn-modal backdropDismiss obsolete

**dnn-modal** `backgroundDismiss` is obsolete, use preventBackgroundDismiss instead.
Per html specifications any boolean attribute should have a false default values, this was not the case for this property and it was replaced with the opposite `preventBackgroundDismiss` property instead (so it has the same default UX without breaking html specs).
**dnn-modal** `backdropDismiss` is obsolete, use preventBackdropDismiss instead.
Per html specifications any boolean attribute should have a false default values, this was not the case for this property and it was replaced with the opposite `preventBackdropDismiss` property instead (so it has the same default UX without breaking html specs).

Example before:
```html
<dnn-modal backgroundDimiss={false}>
<dnn-modal backdropDismiss={false}>
<p>Something</p>
</dnn-modal>
```

Example after:
```html
<dnn-modal preventBackgroundDimiss>
<dnn-modal preventBackdropDismiss>
<p>Something</p>
</dnn-modal>
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ ruleTester.run("dnn-modal-no-background-dismiss", rule, {
languageOptions: jsxParserOptions,
},
{
code: "<dnn-modal preventBackgdropDismiss></dnn-modal>",
code: "<dnn-modal preventBackdropDismiss></dnn-modal>",
languageOptions: jsxParserOptions,
},
],
invalid: [
{
code: "<dnn-modal backgroundDismiss></dnn-modal>",
code: "<dnn-modal backdropDismiss></dnn-modal>",
languageOptions: jsxParserOptions,
errors: [{ messageId: "dnnModalNoBackgroundDismiss" }],
output: "<dnn-modal ></dnn-modal>",
},
{
code: "<dnn-modal backgroundDismiss={true}></dnn-modal>",
code: "<dnn-modal backdropDismiss={true}></dnn-modal>",
languageOptions: jsxParserOptions,
errors: [{ messageId: "dnnModalNoBackgroundDismiss" }],
output: "<dnn-modal ></dnn-modal>",
},
{
code: "<dnn-modal backgroundDismiss={false}></dnn-modal>",
code: "<dnn-modal backdropDismiss={false}></dnn-modal>",
languageOptions: jsxParserOptions,
errors: [{ messageId: "dnnModalNoBackgroundDismiss" }],
output: "<dnn-modal preventBackgroundDismiss></dnn-modal>",
output: "<dnn-modal preventBackdropDismiss></dnn-modal>",
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const rule = createRule({
type: "problem",
fixable: "code",
messages: {
dnnModalNoBackgroundDismiss: "Background dismiss is obsolete in dnn-modal, use preventBackgroundDismiss instead."
dnnModalNoBackgroundDismiss: "Background dismiss is obsolete in dnn-modal, use preventBackdropDismiss instead."
},
schema: [],
},
Expand All @@ -23,17 +23,17 @@ export const rule = createRule({
node.openingElement.name.type === "JSXIdentifier" &&
node.openingElement.name.name === "dnn-modal"
) {
const backgroundDismissAttr = node.openingElement.attributes.find(attr =>
const backdropDismissAttr = node.openingElement.attributes.find(attr =>
attr.type === "JSXAttribute" &&
attr.name.name === "backgroundDismiss"
attr.name.name === "backdropDismiss"
);

if (backgroundDismissAttr?.type === "JSXAttribute") {
if (backdropDismissAttr?.type === "JSXAttribute") {
context.report({
node: backgroundDismissAttr,
node: backdropDismissAttr,
messageId: "dnnModalNoBackgroundDismiss",
fix(fixer) {
const attrValue = backgroundDismissAttr.value;
const attrValue = backdropDismissAttr.value;
const isImplicitTrue = !attrValue;
const isExplicitTrue = attrValue &&
attrValue.type === "JSXExpressionContainer" &&
Expand All @@ -47,19 +47,19 @@ export const rule = createRule({

if (isImplicitTrue || isExplicitTrue) {
// Remove attribute entirely
return fixer.remove(backgroundDismissAttr);
return fixer.remove(backdropDismissAttr);
}

if (isExplicitFalse) {
// Replace with opposite meaning
return fixer.replaceText(
backgroundDismissAttr,
"preventBackgroundDismiss"
backdropDismissAttr,
"preventBackdropDismiss"
);
}

// Default behavior: just remove it
return fixer.remove(backgroundDismissAttr);
return fixer.remove(backdropDismissAttr);
},
});
}
Expand Down
Loading