Skip to content

Commit

Permalink
fix(modal): slug without close-button
Browse files Browse the repository at this point in the history
  • Loading branch information
ariellalgilmore committed Dec 14, 2023
1 parent fdcde3a commit c919a35
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class CDSModalCloseButton extends FocusMixin(LitElement) {
@property({ attribute: 'close-button-label' })
closeButtonLabel = 'Close';

updated() {
this.parentElement.setAttribute('close-button', '');
}

render() {
const { closeButtonLabel } = this;
return html`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ class CDSModalFooter extends LitElement {
private _handleSlotChange(event: Event) {
const { selectorButtons } = this.constructor as typeof CDSModalFooter;
const length = (event.target as HTMLSlotElement)
.assignedNodes()
.filter(
(node) =>
node.nodeType === Node.ELEMENT_NODE &&
(node as Element).matches(selectorButtons)
).length;
.assignedNodes()
.filter(
(node) =>
node.nodeType === Node.ELEMENT_NODE &&
(node as Element).matches(selectorButtons)
).length;
this.hasThreeButtons = length > 2;
length === 2 ? this.parentElement.setAttribute('has-two-buttons', '') : this.parentElement.removeAttribute('has-two-buttons')
length === 2
? this.parentElement.setAttribute('has-two-buttons', '')
: this.parentElement.removeAttribute('has-two-buttons');
this.requestUpdate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CDSModalHeader extends LitElement {
this.requestUpdate();
}

updated(){
updated() {
if (this._hasSlug) {
this.parentElement.setAttribute('slug', '');
} else {
Expand All @@ -53,7 +53,8 @@ class CDSModalHeader extends LitElement {
}

render() {
return html` <slot></slot> <slot name="slug" @slotchange="${this._handleSlotChange}"></slot>`;
return html` <slot></slot>
<slot name="slug" @slotchange="${this._handleSlotChange}"></slot>`;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@
background-color: $layer;
}


:host(#{$prefix}-modal-header) ::slotted(#{$prefix}-slug){
:host(#{$prefix}-modal-header) ::slotted(#{$prefix}-slug) {
position: absolute;
inset-block-start: 0;
inset-inline-end: 3rem;
inset-inline-end: 0;
}

:host(#{$prefix}-modal-header[close-button]) ::slotted(#{$prefix}-slug) {
inset-inline-end: $spacing-09;
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ export const _Dropdown = () => {

export const _Modal = () => {
return html`
<style>${styles}</style>
<style>
${styles}
</style>
<cds-modal open prevent-close>
<cds-modal-header>
<cds-slug alignment="bottom-left"> ${content}${actions}</cds-slug>
<cds-modal-close-button></cds-modal-close-button>
<cds-modal-label>Account resources</cds-modal-label>
<cds-modal-heading>Add a custom domain</cds-modal-heading>
Expand Down Expand Up @@ -270,8 +271,8 @@ export const _Modal = () => {
<cds-modal-footer-button>Add</cds-modal-footer-button>
</cds-modal-footer>
</cds-modal>
`
}
`;
};

export const _Multiselect = () => {
return html` <style>
Expand Down

0 comments on commit c919a35

Please sign in to comment.