-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature / Add column width reset on dblclick #145
Feature / Add column width reset on dblclick #145
Conversation
3355396
to
c5dc4ac
Compare
Thanks so much for the contribution! I'll play around with it, and I'd be more than happy to add a contributing guide. Generally though, I just run manual interaction tests with As for the API, enabling/disabling double-click to reset might actually be better expressed as a plugin option or a column option, something like: const table = createTable(data, {
resize: addResizedColumns({
// default to false?
doubleClickDragHandleToReset: true,
}),
});
// or
const columns = table.createColumns([
table.column({
accessor: 'name',
plugins: {
// for per-column config
resize: {
doubleClickDragHandleToReset: false,
},
},
});
]); Having it default to You can define these properties in the To read the plugin's config state, refer to: export const addResizedColumns =
// here, line 70.
<Item>({ onResizeEnd }: AddResizedColumnsConfig = {}): TablePlugin<
Item,
ResizedColumnsState,
ResizedColumnsColumnOptions,
ResizedColumnsPropSet,
ResizedColumnsAttributeSet
> =>
({ columnOptions }) => { In the plugin's hooks for While I don't have a lot of time, I'd love to help you figure this out! |
Hey @bryanmylee ! I just figured out I needed to install
I think a column option to disable would make sense, since the behaviour is globally set with the attribute Or were you thinking about linking the reset behaviour with Also, thanks for your help and anwser! :) |
Also just realized a neat thing, with {#if !props.resize.disabled}
<button use:props.resize.reset>reset width</button> <!-- here -->
{/if}
{#if !props.resize.disabled}
<div
class="resizer"
on:click|stopPropagation
use:props.resize.drag
use:props.resize.reset
/> <!-- or here ^ -->
{/if} |
Hey @bryanmylee! Thanks for accepting my PR. :D I was just looking back on this yesterday by chance! I don't really had the time to complete with the columns option or else since I've been buried in work for a while now, lol... Anyway, happy to see it was good enough for you! :) See you next PR! |
I tried to implement this in my project, but it was buggy, so I thought I could try to add it directly to your project. Turns out it was so much easier this way!
I added a double click action to reset a column to its initial width.
It also works on touchscreens by listening to
touchend
to simulatedoubletap
without interfering with thedrag
mechanism.Feel free to tell me if I forgot something (types?) as I am not used to Svelte/Kit, NPM packages nor TypeScript.
(Actually, I tried to
package
orbuild
withpnpm
to test the bundled version, but couldn't figure out how to do... I first did the modifications directly injs
files fromnode_modules
in a project I am building, so I tested it this way instead. I'ts probably working, but you might build and test before merging just in case. Also, a contributing guide would be useful! - I know it might be a bit of work to make it tho...)Nice work btw, I love working with
svelte-headless-table
! 😄 (I saw in another comment that you don't have much time to update it at the moment. I'll be happy to contribute if anything else comes to my mind while I'm working 😉)