Skip to content

Commit 571b1c2

Browse files
committed
fix bug
1 parent fefdda5 commit 571b1c2

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

packages/parse5/lib/parser/index.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,51 @@ describe('parser', () => {
172172
expect((b.childNodes[0] as TextNode).value).toBe('should be outside');
173173
});
174174
});
175+
176+
describe('Customizable Select', () => {
177+
it('should NOT enable selectedcontent for select multiple', () => {
178+
const html = `
179+
<select multiple>
180+
<button>
181+
<selectedcontent></selectedcontent>
182+
</button>
183+
<option selected>foo</option>
184+
</select>
185+
`;
186+
187+
const doc = parse(html);
188+
const htmlEl = doc.childNodes.find((n) => n.nodeName === 'html') as Element;
189+
const body = htmlEl.childNodes.find((n) => n.nodeName === 'body') as Element;
190+
const select = body.childNodes.find((n) => (n as Element).tagName === 'select') as Element;
191+
const button = select.childNodes.find((n) => (n as Element).tagName === 'button') as Element;
192+
const selectedcontent = button.childNodes.find(
193+
(n) => (n as Element).tagName === 'selectedcontent',
194+
) as Element;
195+
196+
expect(selectedcontent.childNodes.length).toBe(0);
197+
});
198+
199+
it('should enable selectedcontent for select without multiple', () => {
200+
const html = `
201+
<select>
202+
<button>
203+
<selectedcontent></selectedcontent>
204+
</button>
205+
<option selected>foo</option>
206+
</select>
207+
`;
208+
209+
const doc = parse(html);
210+
const htmlEl = doc.childNodes.find((n) => n.nodeName === 'html') as Element;
211+
const body = htmlEl.childNodes.find((n) => n.nodeName === 'body') as Element;
212+
const select = body.childNodes.find((n) => (n as Element).tagName === 'select') as Element;
213+
const button = select.childNodes.find((n) => (n as Element).tagName === 'button') as Element;
214+
const selectedcontent = button.childNodes.find(
215+
(n) => (n as Element).tagName === 'selectedcontent',
216+
) as Element;
217+
218+
expect(selectedcontent.childNodes.length).toBeGreaterThan(0);
219+
expect((selectedcontent.childNodes[0] as TextNode).value).toBe('foo');
220+
});
221+
});
175222
});

packages/parse5/lib/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ function selectStartTagInBody<T extends TreeAdapterTypeMap>(p: Parser<T>, token:
22922292
p.framesetOk = false;
22932293

22942294
// Initialize selectedcontent state for this select
2295-
p.selectedcontentSelect = p.openElements.current;
2295+
p.selectedcontentSelect = getTokenAttr(token, 'multiple') === null ? p.openElements.current : null;
22962296
p.enabledSelectedcontent = null;
22972297
p.firstOptionInSelect = null;
22982298
p.selectedOptionInSelect = null;

0 commit comments

Comments
 (0)