Skip to content

Commit efd92c4

Browse files
LyndseyButekton-robot
authored andcommitted
update
1 parent fb3f55b commit efd92c4

3 files changed

Lines changed: 44 additions & 42 deletions

File tree

packages/components/src/components/Log/_Log.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ limitations under the License.
1818

1919
.tkn--scroll-buttons {
2020
position: fixed;
21-
right: .75rem;
22-
bottom: 1rem;
21+
inset-inline-end: .75rem;
22+
inset-block-end: 1rem;
2323
display: flex;
2424
flex-direction: column;
2525
gap: 0.5rem;
2626
z-index: 10000;
2727
}
2828
.tkn--scroll-buttons--maximized{
29-
right: 2rem;
29+
inset-inline-end: 2rem;
3030
}
3131

3232
pre.tkn--log {

packages/components/src/components/ScrollButtons/ScrollButtons.jsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,34 @@ export function ScrollButtons() {
108108
};
109109
}, []);
110110

111+
const getScrollBehavior = () => {
112+
const prefersReducedMotion = window.matchMedia(
113+
'(prefers-reduced-motion: reduce)'
114+
).matches;
115+
return prefersReducedMotion ? 'auto' : 'smooth';
116+
};
117+
111118
const scrollToTop = () => {
112119
if (maximizedContainerRef.current) {
113-
maximizedContainerRef.current.scrollTo({ top: 0, behavior: 'smooth' });
120+
maximizedContainerRef.current.scrollTo({
121+
top: 0,
122+
behavior: getScrollBehavior()
123+
});
114124
} else {
115-
window.scrollTo({ top: 0, behavior: 'smooth' });
125+
window.scrollTo({ top: 0, behavior: getScrollBehavior() });
116126
}
117127
};
118128

119129
const scrollToBottom = () => {
120130
if (maximizedContainerRef.current) {
121131
maximizedContainerRef.current.scrollTo({
122132
top: maximizedContainerRef.current.scrollHeight,
123-
behavior: 'smooth'
133+
behavior: getScrollBehavior()
124134
});
125135
} else {
126136
window.scrollTo({
127137
top: document.documentElement.scrollHeight,
128-
behavior: 'smooth'
138+
behavior: getScrollBehavior()
129139
});
130140
}
131141
};
@@ -156,11 +166,7 @@ export function ScrollButtons() {
156166
id="log-scroll-to-start-btn"
157167
kind="secondary"
158168
onClick={scrollToTop}
159-
renderIcon={() => (
160-
<UpToTop>
161-
<title>{scrollTopMessage}</title>
162-
</UpToTop>
163-
)}
169+
renderIcon={UpToTop}
164170
size="md"
165171
tooltipPosition="left"
166172
/>
@@ -173,11 +179,7 @@ export function ScrollButtons() {
173179
id="log-scroll-to-end-btn"
174180
kind="secondary"
175181
onClick={scrollToBottom}
176-
renderIcon={() => (
177-
<DownToBottom>
178-
<title>{scrollBottomMessage}</title>
179-
</DownToBottom>
180-
)}
182+
renderIcon={DownToBottom}
181183
size="md"
182184
tooltipPosition="left"
183185
/>

packages/components/src/components/ScrollButtons/ScrollButtons.test.jsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ describe('ScrollButtons', () => {
5151
});
5252

5353
it('shows scroll-to-bottom button when at the top of scrollable page', async () => {
54-
const { queryByTitle } = render(<ScrollButtons />);
54+
const { queryByLabelText } = render(<ScrollButtons />);
5555

5656
await waitFor(() => {
57-
expect(queryByTitle('Scroll to bottom')).toBeTruthy();
57+
expect(queryByLabelText('Scroll to bottom')).toBeTruthy();
5858
});
59-
expect(queryByTitle('Scroll to top')).toBeFalsy();
59+
expect(queryByLabelText('Scroll to top')).toBeFalsy();
6060
});
6161

6262
it('shows scroll-to-top button when at the bottom of scrollable page', async () => {
63-
const { queryByTitle } = render(<ScrollButtons />);
63+
const { queryByLabelText } = render(<ScrollButtons />);
6464

6565
// Simulate scrolling down
6666
Object.defineProperty(window, 'scrollY', {
@@ -71,12 +71,12 @@ describe('ScrollButtons', () => {
7171
fireEvent.scroll(window);
7272

7373
await waitFor(() => {
74-
expect(queryByTitle('Scroll to top')).toBeTruthy();
74+
expect(queryByLabelText('Scroll to top')).toBeTruthy();
7575
});
7676
});
7777

7878
it('shows both buttons when in middle of page', async () => {
79-
const { queryByTitle } = render(<ScrollButtons />);
79+
const { queryByLabelText } = render(<ScrollButtons />);
8080

8181
// Simulate scrolling to middle
8282
Object.defineProperty(window, 'scrollY', {
@@ -87,13 +87,13 @@ describe('ScrollButtons', () => {
8787
fireEvent.scroll(window);
8888

8989
await waitFor(() => {
90-
expect(queryByTitle('Scroll to top')).toBeTruthy();
91-
expect(queryByTitle('Scroll to bottom')).toBeTruthy();
90+
expect(queryByLabelText('Scroll to top')).toBeTruthy();
91+
expect(queryByLabelText('Scroll to bottom')).toBeTruthy();
9292
});
9393
});
9494

9595
it('hides scroll-to-bottom button when at bottom', async () => {
96-
const { queryByTitle } = render(<ScrollButtons />);
96+
const { queryByLabelText } = render(<ScrollButtons />);
9797

9898
Object.defineProperty(window, 'scrollY', {
9999
writable: true,
@@ -103,16 +103,16 @@ describe('ScrollButtons', () => {
103103
fireEvent.scroll(window);
104104

105105
await waitFor(() => {
106-
expect(queryByTitle('Scroll to top')).toBeTruthy();
107-
expect(queryByTitle('Scroll to bottom')).toBeFalsy();
106+
expect(queryByLabelText('Scroll to top')).toBeTruthy();
107+
expect(queryByLabelText('Scroll to bottom')).toBeFalsy();
108108
});
109109
});
110110

111111
it('scrolls to top when scroll to top button is clicked', async () => {
112112
const scrollToSpy = vi.fn();
113113
window.scrollTo = scrollToSpy;
114114

115-
const { queryByTitle } = render(<ScrollButtons />);
115+
const { queryByLabelText } = render(<ScrollButtons />);
116116

117117
// scroll down first
118118
Object.defineProperty(window, 'scrollY', {
@@ -123,10 +123,10 @@ describe('ScrollButtons', () => {
123123
fireEvent.scroll(window);
124124

125125
await waitFor(() => {
126-
expect(queryByTitle('Scroll to top')).toBeTruthy();
126+
expect(queryByLabelText('Scroll to top')).toBeTruthy();
127127
});
128128

129-
const scrollTopButton = queryByTitle('Scroll to top');
129+
const scrollTopButton = queryByLabelText('Scroll to top');
130130
fireEvent.click(scrollTopButton);
131131

132132
expect(scrollToSpy).toHaveBeenCalledWith({
@@ -139,13 +139,13 @@ describe('ScrollButtons', () => {
139139
const scrollToSpy = vi.fn();
140140
window.scrollTo = scrollToSpy;
141141

142-
const { queryByTitle } = render(<ScrollButtons />);
142+
const { queryByLabelText } = render(<ScrollButtons />);
143143

144144
await waitFor(() => {
145-
expect(queryByTitle('Scroll to bottom')).toBeTruthy();
145+
expect(queryByLabelText('Scroll to bottom')).toBeTruthy();
146146
});
147147

148-
const scrollBottomButton = queryByTitle('Scroll to bottom');
148+
const scrollBottomButton = queryByLabelText('Scroll to bottom');
149149
fireEvent.click(scrollBottomButton);
150150

151151
expect(scrollToSpy).toHaveBeenCalledWith({
@@ -155,7 +155,7 @@ describe('ScrollButtons', () => {
155155
});
156156

157157
it('handles maximized container scroll events', async () => {
158-
const { queryByTitle, container } = render(<ScrollButtons />);
158+
const { queryByLabelText, container } = render(<ScrollButtons />);
159159

160160
// Create container first, then add the maximized class to trigger MutationObserver later
161161
const maximizedContainer = document.createElement('div');
@@ -184,7 +184,7 @@ describe('ScrollButtons', () => {
184184

185185
// Wait for MutationObserver to detect the class change and apply maximized class
186186
await waitFor(() => {
187-
expect(queryByTitle('Scroll to bottom')).toBeTruthy();
187+
expect(queryByLabelText('Scroll to bottom')).toBeTruthy();
188188
const scrollButtonsContainer = container.querySelector(
189189
'.tkn--scroll-buttons'
190190
);
@@ -205,12 +205,12 @@ describe('ScrollButtons', () => {
205205

206206
// Both buttons should be visible
207207
await waitFor(() => {
208-
expect(queryByTitle('Scroll to top')).toBeTruthy();
209-
expect(queryByTitle('Scroll to bottom')).toBeTruthy();
208+
expect(queryByLabelText('Scroll to top')).toBeTruthy();
209+
expect(queryByLabelText('Scroll to bottom')).toBeTruthy();
210210
});
211211

212212
// test scroll-to-top button in maximized mode
213-
const scrollTopButton = queryByTitle('Scroll to top');
213+
const scrollTopButton = queryByLabelText('Scroll to top');
214214
fireEvent.click(scrollTopButton);
215215

216216
expect(containerScrollToSpy).toHaveBeenCalledWith({
@@ -219,7 +219,7 @@ describe('ScrollButtons', () => {
219219
});
220220

221221
// test scroll-to-bottom button in maximized mode
222-
const scrollBottomButton = queryByTitle('Scroll to bottom');
222+
const scrollBottomButton = queryByLabelText('Scroll to bottom');
223223
fireEvent.click(scrollBottomButton);
224224

225225
expect(containerScrollToSpy).toHaveBeenCalledWith({
@@ -236,8 +236,8 @@ describe('ScrollButtons', () => {
236236
fireEvent.scroll(maximizedContainer);
237237

238238
await waitFor(() => {
239-
expect(queryByTitle('Scroll to top')).toBeTruthy();
240-
expect(queryByTitle('Scroll to bottom')).toBeFalsy();
239+
expect(queryByLabelText('Scroll to top')).toBeTruthy();
240+
expect(queryByLabelText('Scroll to bottom')).toBeFalsy();
241241
});
242242
});
243243

0 commit comments

Comments
 (0)