Skip to content

Commit

Permalink
Added button text editing to CTA Card (#1416)
Browse files Browse the repository at this point in the history
ref https://linear.app/ghost/issue/PLG-312/implement-button-text-update

- Added ability to update the text of a button
- added test
  • Loading branch information
ronaldlangeveld authored Jan 23, 2025
1 parent 8e9268a commit 1b01b14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const CallToActionNodeComponent = ({
});
};

const handleButtonTextChange = (event) => {
editor.update(() => {
const node = $getNodeByKey(nodeKey);
node.buttonText = event.target.value;
});
};

return (
<>
<CtaCard
Expand All @@ -60,7 +67,7 @@ export const CallToActionNodeComponent = ({
setEditing={setEditing}
showButton={showButton}
text={textValue}
updateButtonText={() => {}}
updateButtonText={handleButtonTextChange}
updateButtonUrl={() => {}}
updateHasSponsorLabel={() => {}}
updateLayout={() => {}}
Expand Down
8 changes: 8 additions & 0 deletions packages/koenig-lexical/test/e2e/cards/cta-card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ test.describe('Call To Action Card', async () => {
expect(await page.isVisible('[data-testid="button-text"]')).toBe(false);
expect(await page.isVisible('[data-testid="button-url"]')).toBe(false);
});

test('can set button text', async function () {
await focusEditor(page);
await insertCard(page, {cardName: 'call-to-action'});
await page.click('[data-testid="button-settings"]');
await page.fill('[data-testid="button-text"]', 'Click me');
expect(await page.textContent('[data-testid="cta-button"]')).toBe('Click me');
});
});

0 comments on commit 1b01b14

Please sign in to comment.