Skip to content

Add support for the progress bar.#90

Open
bhubbard wants to merge 2 commits intortCamp:developfrom
bhubbard:88-progress-bar-block
Open

Add support for the progress bar.#90
bhubbard wants to merge 2 commits intortCamp:developfrom
bhubbard:88-progress-bar-block

Conversation

@bhubbard
Copy link
Copy Markdown
Contributor

This would support issue #88 - Add support for progress bar.

This would support issue rtCamp#88 - Add support for progress bar.
@theMasudRana theMasudRana self-assigned this Mar 26, 2026
Copy link
Copy Markdown
Collaborator

@theMasudRana theMasudRana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The progress bar implementation was great.
I updated the implementation to make it work on the editor and address some accessibility issues for consistency.

Everything works as expected—approved!

cc: @bhubbard @danish17

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “Carousel Progress” inner block to Carousel Kit and wires it to Embla’s scroll progress so the editor and frontend can render a progress bar similar to carousel dots.

Changes:

  • Introduces a new carousel-kit/carousel-progress block (block.json, edit/save, styles).
  • Tracks scrollProgress from Embla in both the frontend interactivity store and the editor context.
  • Registers the new block server-side for discovery/loading.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/blocks/carousel/view.ts Adds a progress-bar style callback and updates scrollProgress from Embla events.
src/blocks/carousel/types.ts Extends carousel types to include progress block attributes and scrollProgress in CarouselContext.
src/blocks/carousel/progress/style.scss Adds frontend styling for the progress bar.
src/blocks/carousel/progress/save.tsx Adds frontend markup wired to interactivity callbacks.
src/blocks/carousel/progress/edit.tsx Adds editor rendering using EditorCarouselContext.
src/blocks/carousel/progress/index.ts Registers the new progress block.
src/blocks/carousel/progress/block.json Declares the new progress block metadata.
src/blocks/carousel/editor-context.ts Adds scrollProgress to the editor carousel context.
src/blocks/carousel/edit.tsx Subscribes to Embla events to keep editor scrollProgress updated.
inc/Plugin.php Registers the new carousel/progress block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

scrollSnaps: { index: number }[];
canScrollPrev: boolean;
canScrollNext: boolean;
scrollProgress: number;
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CarouselContext now requires scrollProgress, but the initial CarouselContext object created in src/blocks/carousel/save.tsx (and several type tests) does not provide this field. This will break TypeScript compilation; either initialize scrollProgress in the saved context (e.g., 0) everywhere a CarouselContext literal is created, or make scrollProgress optional in the type and handle the default in view callbacks.

Suggested change
scrollProgress: number;
scrollProgress?: number;

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +15
const { scrollProgress, slideCount } = useContext( EditorCarouselContext ) as { scrollProgress?: number, slideCount?: number };

// Hide if only one slide
if (slideCount === 1) return null;

Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slideCount is being read from EditorCarouselContext via an as { scrollProgress?: number, slideCount?: number } cast, but EditorCarouselContextType does not define/provide slideCount. As a result slideCount will always be undefined and the if (slideCount === 1) early return will never run. Compute slideCount via useSelect (similar to viewport/edit.tsx) or extend the editor context/provider to supply it.

Suggested change
const { scrollProgress, slideCount } = useContext( EditorCarouselContext ) as { scrollProgress?: number, slideCount?: number };
// Hide if only one slide
if (slideCount === 1) return null;
const { scrollProgress } = useContext( EditorCarouselContext ) as { scrollProgress?: number };

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +18
aria-valuemax={100}
data-wp-bind--style="callbacks.getProgressBarStyle"
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a determinate role="progressbar", ARIA requires the current value to be exposed (e.g. aria-valuenow). Right now the frontend markup only updates width via data-wp-bind--style, so assistive tech won’t get the progress value. Bind aria-valuenow (and optionally aria-valuetext) to a callback derived from scrollProgress so it stays in sync with the visual bar.

Suggested change
aria-valuemax={100}
data-wp-bind--style="callbacks.getProgressBarStyle"
aria-valuemax={100}
aria-valuenow={0}
data-wp-bind--style="callbacks.getProgressBarStyle"
data-wp-bind--aria-valuenow="callbacks.getProgressValue"

Copilot uses AI. Check for mistakes.
Comment on lines +234 to +236
embla.on( 'scroll', () => {
context.scrollProgress = embla.scrollProgress();
} );
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Embla scroll event can fire very frequently; directly writing to the interactivity context on every event may cause excessive DOM/style updates. Consider throttling updates (e.g., via requestAnimationFrame) and/or only updating when the computed progress value actually changes beyond a small epsilon.

Copilot uses AI. Check for mistakes.
Comment on lines +136 to +141
getProgressBarStyle: () => {
const { scrollProgress } = getContext<CarouselContext>();
return {
width: `${ ( scrollProgress || 0 ) * 100 }%`,
};
},
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New callbacks.getProgressBarStyle is introduced but the existing src/blocks/carousel/__tests__/view.test.ts suite doesn’t exercise this callback or validate that scrollProgress is updated from Embla. Adding/adjusting tests for the new callback and state updates would help prevent regressions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants