react-pdf-viewer icon indicating copy to clipboard operation
react-pdf-viewer copied to clipboard

Is there a way to tie into the onClick function in bookmarks?

Open kdv24 opened this issue 3 years ago • 2 comments

We'd like to close the bookmark window for mobile or small screen users once they click on a given bookmark. As it is, the bookmarks panel covers the mobile viewport enough that it's hard to have context.

kdv24 avatar Aug 03 '22 17:08 kdv24

Thanks for your request. I will support it in the next version.

phuocng avatar Aug 04 '22 02:08 phuocng

That's fabulous! Thank you!

kdv24 avatar Aug 04 '22 19:08 kdv24

@kdv24 The feature is implemented in the latest code, and will be included in the next v3.7.0.

Demo

Clicking a bookmark item will close the bookmark tab. You can do something else

https://user-images.githubusercontent.com/57786711/184640544-9a6a1c17-4c53-4184-a133-79f184ba1c66.mp4

API

You can see the sample code here.

const toggleBookmarkTab = () => {
    toggleTab(1);
};

const renderBookmarkItem = (renderProps: RenderBookmarkItemProps) =>
    renderProps.defaultRenderItem(
        renderProps.onClickItem,
        <>
            {renderProps.defaultRenderToggle(<ExpandIcon />, <CollapseIcon />)}
            {renderProps.defaultRenderTitle(() => {
                // ---> Executed when clicking a bookmark item
                renderProps.onClickTitle();
                toggleBookmarkTab();
            })}
        </>
    );

const defaultLayoutPluginInstance = defaultLayoutPlugin({
    ...
});

const { toggleTab } = defaultLayoutPluginInstance;
const bookmarkPluginInstance = defaultLayoutPluginInstance.bookmarkPluginInstance;
const { Bookmarks } = bookmarkPluginInstance;

phuocng avatar Aug 15 '22 13:08 phuocng

Great! Thank you @phuocng!

kdv24 avatar Aug 15 '22 13:08 kdv24

@kdv24 The example is now available on the official website https://react-pdf-viewer.dev/examples/execute-a-function-when-users-click-a-bookmark-item/

phuocng avatar Sep 04 '22 04:09 phuocng