-
Notifications
You must be signed in to change notification settings - Fork 132
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
Implement method to process attributes that can be overridden by slots #2511
Implement method to process attributes that can be overridden by slots #2511
Conversation
and use it for attributes that can be overridden by slots
} | ||
|
||
processPopoverAttributes(node: MbNode) { | ||
this.processSlotAttribute(node, 'header', true); | ||
|
||
// Warn if there is a content slot overriding the attributes 'content' or 'src' | ||
const hasSlotAndContentAttribute = this.hasSlotOverridingAttribute(node, 'content', 'content'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit was left unchanged because the logic for the content
attribute is slightly different. According to the docs, the src
and content
attributes and the content
slot can be used for popovers. If all three are present then MarkBind will prioritise them in the following order:
content
slotcontent
attributesrc
attribute
So the logic to process this attribute (and especially the logger warning) is different than the other attributes. Specifically, it needs to check for the case that the src
and content
attributes are both used, and show a warning message if that is the case. The processSlotAttribute
method does not account for this case, so this chunk of code is still here.
* @param isInline Whether to process the attribute with only inline markdown-it rules | ||
* @param slotName Name attribute of the <slot> element to insert, which defaults to the attribute name | ||
*/ | ||
processSlotAttribute(node: MbNode, attribute: string, isInline: boolean, slotName = attribute) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely happy with the name of the method but it's the best I can come up with. Some other alternatives I've considered are:
processSlottableAttribute
processAttributeCanBeOverridden
processOverridableAttribute
processAttributeWithSlot
Let me know your thoughts thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think processSlotAttribute is ok!
The The warnings arise from the panel in the Header and Hint example with slots at this page (the relevant documentation file is <question type="checkbox" header="Which of the following is true?" hint="Think out of the box! :fas-box:">
<!-- Header slot -->
<div slot="header">
<p>Which of the following is correct?</p>
<p>Challenge: Try to get all the answers on your first try! ⭐️ ⭐️</p>
</div>
<!-- other code omitted for brevity -->
<!-- Hint slot -->
<div slot="hint">
<p>Think out of the box! <span aria-hidden="true" class="fas fa-box"></span></p>
<p>Need another hint? <tooltip content="Two of the answers are correct!">Hover over me!</tooltip> <span aria-hidden="true" class="fas fa-mouse-pointer"></span></p>
</div>
</question> As can be seen, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed PR @luminousleek!
I realized that our documentation might not be fully up to date - other attributes seem to work with a slot as well (like a-point) but it doesn't seem to be present in our documentation.
I think we might need to double check this behavior and update the documentation
* @param isInline Whether to process the attribute with only inline markdown-it rules | ||
* @param slotName Name attribute of the <slot> element to insert, which defaults to the attribute name | ||
*/ | ||
processSlotAttribute(node: MbNode, attribute: string, isInline: boolean, slotName = attribute) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think processSlotAttribute is ok!
The docs currently has a question where there are slots overriding the header attributes. However, when #2511 is merged, logger warnings about this overriding will be triggered, leading to the check-docs GitHub action failing. Let's remove the header attributes so that they will not trigger the logger warning. Let's also update the sample code to reflect this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. I think we can leave the documentation for another PR or concurrent with adding tests for the ones that aren't tested yet.
I like how this makes the code overall clearer by using a simpler method for everything, thanks for your work!
The docs currently has a question where there are slots overriding the header attributes. However, when MarkBind#2511 is merged, logger warnings about this overriding will be triggered, leading to the check-docs GitHub action failing. Let's remove the header attributes so that they will not trigger the logger warning. Let's also update the sample code to reflect this change.
@kaixin-hc Each PR must have a SEMVER impact label, please remember to label the PR properly. |
What is the purpose of this pull request?
Partially resolves #2476
Overview of changes:
Implement
processSlotAttribute
method and use it for attributes that can be overridden by slots.Anything you'd like to highlight/discuss:
For reference, these are the attributes that can be overridden by slots:
The docs are not correct regarding this.
Testing instructions:
Proposed commit message: (wrap lines at 72 characters)
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major
,r.Minor
,r.Patch
.Breaking change release note preparation (if applicable):