@nys-cui/cui-section 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "main": "./dist/js/section.js",
8
8
  "type": "module",
9
- "version": "0.2.1",
9
+ "version": "0.2.3",
10
10
  "scripts": {
11
11
  "clean": "rm -rf ./dist",
12
12
  "build": "npm run clean && cui --dep",
package/src/section.js CHANGED
@@ -73,6 +73,7 @@ export default class CUI_SECTION extends HTMLElement {
73
73
 
74
74
  // remove "height" from the dContainer's inline styles, so it can return to its initial value
75
75
  dContainer.style.height = "";
76
+ dContainer.style.overflow = null;
76
77
 
77
78
  // mark the section as "currently not collapsed"
78
79
  dContainer.setAttribute('data-collapsed', 'false');
@@ -91,6 +92,7 @@ export default class CUI_SECTION extends HTMLElement {
91
92
 
92
93
  // have the dContainer transition to the height of its inner content
93
94
  dContainer.style.height = sectionHeight + 'px';
95
+ dContainer.style.overflow = "hidden";
94
96
 
95
97
  // when the next css transition finishes (which should be the one we just triggered)
96
98
  dContainer.addEventListener('transitionend', transitionEnd, true);
@@ -101,13 +103,14 @@ export default class CUI_SECTION extends HTMLElement {
101
103
  collapse(dContainer) {
102
104
 
103
105
  function transitionEnd(e) {
106
+
107
+ dContainer.style.height = "";
108
+ dContainer.style.overflow = null;
104
109
 
105
110
  // mark the section as "currently collapsed"
106
111
  dContainer.setAttribute('data-collapsed', 'true');
107
112
  dContainer.setAttribute('aria-expanded', 'false');
108
113
 
109
- dContainer.style.height = "";
110
-
111
114
  dContainer.removeEventListener('transitionend', transitionEnd, true);
112
115
  }
113
116
 
@@ -126,7 +129,7 @@ export default class CUI_SECTION extends HTMLElement {
126
129
  requestAnimationFrame(function() {
127
130
  dContainer.style.height = sectionHeight + 'px';
128
131
  dContainer.style.transition = dContainerTransition;
129
-
132
+ dContainer.style.overflow = "hidden";
130
133
 
131
134
  // on the next frame (as soon as the previous style change has taken effect),
132
135
  // have the dContainer transition to height: 0
@@ -143,21 +146,11 @@ export default class CUI_SECTION extends HTMLElement {
143
146
 
144
147
  }
145
148
 
146
- animationstart() {
147
-
148
- console.log("Animation started");
149
- }
150
-
151
- animationend() {
152
-
153
- console.log("Animation ended");
154
- }
155
-
156
149
  connectedCallback() {
157
150
 
158
151
  this.state = {
159
152
  sTitle: this.getAttribute('sectiontitle') || "SECTION TITLE",
160
- bHideControls: (this.getAttribute("hideControls") === "true") ? true : false,
153
+ bHideControls: this.hasAttribute("hideControls") ? true : false,
161
154
  bCollapsed: (this.getAttribute('collapsed') === "true") ? true : false,
162
155
  asStyles: (this.getAttribute('styles')) ? this.getAttribute('styles').split(',') : null
163
156
  }
@@ -175,17 +168,9 @@ export default class CUI_SECTION extends HTMLElement {
175
168
  this.sdSectionTitle = this.shadowRoot.querySelector(`#section-title`);
176
169
  this.sdContentsContainer = this.shadowRoot.querySelector(`#container`);
177
170
 
178
- if (this.bCollapsed) {
179
- this.sdContentsContainer.setAttribute('aria-expanded', 'false');
180
- }
181
- else {
182
- this.sdContentsContainer.setAttribute('aria-expanded', 'true');
183
- }
184
-
185
-
186
171
  this.sdSectionTitle.appendChild(document.createTextNode(this.state.sTitle));
187
172
 
188
- if (!this.state.bHideControls) {
173
+ if (!this.state.bHideControls) {
189
174
 
190
175
  this.sdSectionCollapseControl = this.shadowRoot.querySelector(`#collapse-control`);
191
176
 
@@ -197,7 +182,6 @@ export default class CUI_SECTION extends HTMLElement {
197
182
 
198
183
  this.sdSectionCollapseControl.classList.add('collapsed');
199
184
  this.sdContentsContainer.setAttribute('data-collapsed', "true");
200
- this.sdContentsContainer.setAttribute('aria-expanded', "false");
201
185
  }
202
186
 
203
187
  this.sdSectionCollapseControl.addEventListener('click', () => {
package/src/section.scss CHANGED
@@ -1,6 +1,7 @@
1
1
  :host {
2
2
  display: block;
3
3
  margin-bottom: 20px;
4
+ width: 100%;
4
5
 
5
6
  * {
6
7
  box-sizing: border-box;
@@ -63,17 +64,20 @@
63
64
  }
64
65
 
65
66
  .container {
67
+ box-sizing:content-box;
66
68
  //margin: 0 0.75em 20px;
67
69
  //margin: 0 0.75em;
68
- transition: height 0.5s ease;
69
- overflow: hidden;
70
+ transition: height 0.5s ease;
70
71
 
71
72
  &[data-collapsed="true"] {
72
73
  height: 0;
74
+ overflow: hidden;
73
75
  }
74
76
 
75
- &[aria-expanded="false"] {
76
- display: none;
77
+ // Prevent margin collapse of section contents when collapsing/expanding.
78
+ &::before, &::after{
79
+ content: ' ';
80
+ display: table;
77
81
  }
78
82
 
79
83
  }