Skip to content

Commit

Permalink
Setting translate through direct access does not work (#3800)
Browse files Browse the repository at this point in the history
* Setting translate through direct access does not work

* add test

* alternative fix
  • Loading branch information
JoviDeCroock authored Feb 8, 2024
1 parent 6992228 commit 72cbd2d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ function handleDomVNode(vnode) {
// value will be used as the file name and the file will be called
// "true" upon downloading it.
value = '';
} else if (lowerCased === 'translate' && value === 'no') {
value = false;
} else if (lowerCased === 'ondoubleclick') {
i = 'ondblclick';
} else if (
Expand Down
10 changes: 10 additions & 0 deletions compat/test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,16 @@ describe('compat render', () => {
expect(updateSpy).to.not.be.calledOnce;
});

it('should support the translate attribute w/ yes as a string', () => {
render(<b translate="yes">Bold</b>, scratch);
expect(scratch.innerHTML).to.equal('<b translate="yes">Bold</b>');
});

it('should support the translate attribute w/ no as a string', () => {
render(<b translate="no">Bold</b>, scratch);
expect(scratch.innerHTML).to.equal('<b translate="no">Bold</b>');
});

it('should support false aria-* attributes', () => {
render(<div aria-checked={false} />, scratch);
expect(scratch.firstChild.getAttribute('aria-checked')).to.equal('false');
Expand Down
2 changes: 1 addition & 1 deletion src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ export namespace JSXInternal {
| undefined
| SignalLike<boolean | undefined>;
results?: number | undefined | SignalLike<number | undefined>;
translate?: 'yes' | 'no' | undefined | SignalLike<'yes' | 'no' | undefined>;
translate?: boolean | undefined | SignalLike<boolean | undefined>;

// RDFa Attributes
about?: string | undefined | SignalLike<string | undefined>;
Expand Down
10 changes: 10 additions & 0 deletions test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ describe('render()', () => {
expect(scratch.firstChild).to.have.property('nodeName', 'X-BAR');
});

it('should support the translate attribute w/ false as a boolean', () => {
render(<b translate={false}>Bold</b>, scratch);
expect(scratch.innerHTML).to.equal('<b translate="no">Bold</b>');
});

it('should support the translate attribute w/ true as a boolean', () => {
render(<b translate>Bold</b>, scratch);
expect(scratch.innerHTML).to.equal('<b translate="yes">Bold</b>');
});

it('should support the form attribute', () => {
render(
<div>
Expand Down

0 comments on commit 72cbd2d

Please sign in to comment.