Skip to content

Commit

Permalink
fix(go-dialog): preserve attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
seanwuapps committed Nov 25, 2023
1 parent e672823 commit c381a40
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
23 changes: 11 additions & 12 deletions packages/core/src/components/go-dialog/go-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, h, Element, Prop, Method, Watch } from '@stencil/core';
import { uniqueId } from 'lodash-es';
import { inheritAttributes } from '../../utils/helper';

@Component({
tag: 'go-dialog',
Expand Down Expand Up @@ -28,12 +27,6 @@ export class GoDialog {

overlayEl: HTMLElement;

// Store attributes inherited from the host element
private inheritedAttrs = {};
componentWillLoad() {
this.inheritedAttrs = inheritAttributes(this.el, ['class', 'style']);
}

@Method()
async close() {
this.active = false;
Expand All @@ -59,7 +52,7 @@ export class GoDialog {
}

render() {
const { active, heading, persistent, headingId, inheritedAttrs } = this;
const { active, heading, persistent, headingId } = this;
return (
<go-overlay
class="go-dialog"
Expand All @@ -70,15 +63,22 @@ export class GoDialog {
active={active}
aria-hidden={active ? 'false' : 'true'}
ref={(el) => (this.overlayEl = el)}
onOverlayClose={() => this.handleOverlayClose()}
{...inheritedAttrs}>
onOverlayClose={() => this.handleOverlayClose()}>
<div class="overlay-heading" id={headingId}>
<slot name="heading">
<h3>{heading}</h3>
</slot>
{!persistent ? (
<go-button class="close-btn" flat stack color="tertiary" compact onClick={() => this.close()}>
<go-button
class="close-btn"
flat
icon
stack
variant="text"
onClick={() => this.close()}
aria-label="Close dialog">
<svg
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
stroke="currentColor"
Expand All @@ -88,7 +88,6 @@ export class GoDialog {
viewBox="0 0 24 24">
<path d="M18 6 6 18M6 6l12 12" />
</svg>
<span>Close</span>
</go-button>
) : null}
</div>
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Used in Docusaurus demo component -->
<!DOCTYPE html>
<html dir="ltr" lang="en">
<html dir="ltr" lang="en" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
Expand All @@ -21,6 +21,15 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<go-main-nav id="main-nav"></go-main-nav>
<go-nav-list block id="nav-list"></go-nav-list>

<go-dialog heading="Dialog content" active>
<p>demo</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorem quidem aut laudantium sint perspiciatis fugit,
quos voluptatum facilis. Delectus fugiat deserunt cumque adipisci alias voluptates, atque facere beatae
aspernatur nihil!
</p>
</go-dialog>
<script>
const mainNav = document.getElementById('main-nav');
const navList = document.getElementById('nav-list');
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
Expand Down
7 changes: 6 additions & 1 deletion packages/vue/src/demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
</div>
</div>
</main>

<!-- quickSaveDialog -->
<GoDialog ref="quickSaveDialog" heading="Quick save" active>
<h1>demo</h1>
</GoDialog>
</template>

<script setup lang="ts">
import { GoToc } from '@';
import { GoToc, GoDialog } from '@';
import FormSections from './components/FormSections.vue';
</script>

1 comment on commit c381a40

@vercel
Copy link

@vercel vercel bot commented on c381a40 Nov 25, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.